ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Spring-boot读书笔记一where is rating() from

Spring-boot读书笔记一where is rating() from

where the rating() method comes from:

In the Course entity:

@Column(name = "RATING")
private int rating;

The @Data annotation generates:

  • getRating() method - returns the value of the rating field
  • setRating(int rating) method - sets the rating field value
    So course.getRating() returns the actual rating value (e.g., 5, 4, 3, etc.)

In the CourseNameRating builder:

@Builder
@Data
private static class CourseNameRating {String name;int rating;  // ← This field
}

The @Builder annotation generates a builder class with:

  • name(String name) method - for setting the name in the builder
  • rating(int rating) method - for setting the rating in the builder ← This is where rating() comes from

The flow:

  • course.getRating() - gets the rating value from Course entity (e.g., returns 5)
  • CourseNameRating.builder().rating(5) - passes that value to the builder's rating() method
  • The builder's rating() method sets the rating field in the new CourseNameRating object

So the rating() method exists in the CourseNameRating builder class (generated by @Builder), not in the Course entity. The Course entity has getRating() method (generated by @Data).

返回列表