【发布时间】:2022-07-12 00:44:44
【问题描述】:
我在 Spring Boot 中有许多控制器从集合中读取我的文档。其中一个是这样的:
@GetMapping("/getRandomSummerCamps")
public List<AdventureHolidays> getRandomSummerCamps() {
return adventureHolidaysService.getRandomSummerCamps();
}
所以它是带有服务和存储库的临时控制器。我的目标是什么,我找不到合适的方法。例如,该控制器向我返回这样的 API:
[{"title":"Raquette Lake Camp","description":"Founded in 1916, Raquette Lake Camp enjoys a reputation as the Harvard of summer camps, with extensive programs, state of the art lodgings, required uniforms, on-site chefs, and a difficult, exclusive application process. Those who are not grandfathered in as siblings of previous members must undergo an interview process for approximately 10 to 12 extra spots per year. Divided into both a boys camp and a girls camp separated by a lake, activities are wide and varied: gymnastics, ice hockey, horseback riding, canoeing, sailing, lacrosse, baseball, and tennis are but a few of the sports offered, while the theater and arts program are also well-regarded. At the end of summer, campers participate in a weeklong Color War, divided into two groups of green and white for boys, and blue and white for girls. While the sexes are segregated and each camp is run separately, the brother and sister camps lunch together weekly.","typeOfAdventureHolidays":"summerCamps"}]
从该 JSON 中,我想使用 title 和 description。我怎样才能做到这一点,所以当我调用该控制器时,它返回给我的 HTML 页面只有 title 和 descritpion?
这也是该控制器的模型。
@Document("adventureholidays")
public class AdventureHolidays {
@Id
private String id;
private String title;
private String description;
private String typeOfAdventureHolidays;
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public String getTypeOfAdventureHolidays() {
return typeOfAdventureHolidays;
}
提前谢谢大家,抱歉英语不好,不是母语。
【问题讨论】:
标签: java html spring-boot