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

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:

主站蜘蛛池模板: 洛扎县| 电白县| 大同县| 舒城县| 泰顺县| 碌曲县| 通榆县| 济南市| 思茅市| 苗栗市| 梨树县| 红原县| 英吉沙县| 德清县| 龙南县| 望谟县| 安塞县| 曲麻莱县| 武夷山市| 宝兴县| 西和县| 米林县| 平凉市| 错那县| 嘉禾县| 铜陵市| 嘉善县| 手游| 道真| 通许县| 沈阳市| 贺兰县| 临泉县| 肥乡县| 涪陵区| 克东县| 大足县| 黄大仙区| 黄龙县| 二手房| 奉新县|