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

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:

主站蜘蛛池模板: 凌云县| 朔州市| 石屏县| 肇庆市| 河池市| 增城市| 榆中县| 楚雄市| 镇远县| 自治县| 德清县| 吉林省| 安陆市| 三门峡市| 南皮县| 勃利县| 黄骅市| 同心县| 武定县| 东平县| 金溪县| 扎囊县| 乡宁县| 张家港市| 会同县| 绩溪县| 谷城县| 五莲县| 巍山| 安岳县| 中江县| 平陆县| 监利县| 乐陵市| 延安市| 尼玛县| 双鸭山市| 安多县| 句容市| 古蔺县| 钟山县|