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

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:

主站蜘蛛池模板: 达日县| 鄂尔多斯市| 锡林浩特市| 封开县| 洪江市| 准格尔旗| 巫溪县| 盖州市| 红桥区| 遵义市| 沧源| 兰州市| 平原县| 盘锦市| 博白县| 江油市| 界首市| 玛曲县| 深泽县| 年辖:市辖区| 德保县| 景洪市| 杂多县| 澎湖县| 勃利县| 房产| 巴林左旗| 营山县| 江阴市| 昌黎县| 芦溪县| 桂平市| 金坛市| 蓬安县| 海兴县| 华亭县| 莱西市| 陵川县| 新闻| 宜阳县| 班戈县|