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

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:

主站蜘蛛池模板: 介休市| 漳浦县| 呼图壁县| 伊宁市| 柘城县| 扶沟县| 合山市| 鸡西市| 宁远县| 宜州市| 宁海县| 五河县| 休宁县| 交城县| 娱乐| 方城县| 襄樊市| 上高县| 武鸣县| 仁怀市| 临漳县| 邯郸县| 九龙坡区| 道真| 康马县| 北京市| 江山市| 晋江市| 长春市| 盖州市| 布尔津县| 彭州市| 利津县| 深泽县| 吴堡县| 颍上县| 封开县| 海伦市| 铜川市| 板桥市| 绵竹市|