官术网_书友最值得收藏!

  • Cloud-Native Applications in Java
  • Ajay Mahajan Munish Kumar Gupta Shyam Sundar
  • 135字
  • 2021-06-24 19:07:16

Writing service and domain objects

The annotations in Spring Boot make it easy to extract parameters and path variables and execute the service. For now, let's mock the response instead of getting the data from the database.

Create a simple Java entity called the Product class. For now, it is a simple Plain Old Java Object (POJO) class with three fields:

publicclass Product {
privateint id = 1 ;
private String name = "Oranges " ;
privateint catId = 2 ;

Add the getter and setter methods and a constructor that accepts the product ID:

  public Product(int id) {
this.id = id;
}

Also, add an empty constructor that will be used by the service client, as we will see later:

  public Product() {
}

Then, write the ProductService class as follows:

主站蜘蛛池模板: 宁陕县| 叙永县| 宜章县| 唐河县| 建宁县| 漯河市| 通化市| 鹤岗市| 新乡市| 且末县| 兴义市| 宁津县| 勃利县| 临漳县| 吴堡县| 连云港市| 固安县| 平原县| 宁南县| 奈曼旗| 兰西县| 珠海市| 册亨县| 鄯善县| 梧州市| 华亭县| 东丽区| 磴口县| 夏津县| 河源市| 岐山县| 新河县| 新巴尔虎左旗| 武功县| 庆城县| 普洱| 合阳县| 同德县| 芒康县| 石城县| 潜山县|