
上QQ阅读APP看书,第一时间看更新
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:
