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

  • 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:

主站蜘蛛池模板: 昭觉县| 远安县| 宝鸡市| 青河县| 应城市| 柳河县| 连平县| 上犹县| 福贡县| 娄底市| 通州市| 育儿| 连江县| 平塘县| 大港区| 安西县| 乌审旗| 彩票| 涿鹿县| 赣州市| 石台县| 宜春市| 湘西| 花垣县| 蓬溪县| 当涂县| 江城| 南陵县| 务川| SHOW| 临颍县| 长垣县| 汾阳市| 定边县| 利津县| 青神县| 尼勒克县| 元朗区| 铁岭县| 长岭县| 轮台县|