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

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:

主站蜘蛛池模板: 涞水县| 辽中县| 长岭县| 杭州市| 葫芦岛市| 崇左市| 绥江县| 教育| 繁昌县| 沐川县| 上高县| 随州市| 长葛市| 金寨县| 会泽县| 磐安县| 内丘县| 大埔县| 攀枝花市| 西青区| 兴城市| 宁德市| 公安县| 饶平县| 噶尔县| 策勒县| 松原市| 洪洞县| 昆山市| 瓮安县| 新源县| 乳山市| 青龙| 朔州市| 镇沅| 英德市| 东港市| 丁青县| 基隆市| 翼城县| 普安县|