-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
一些关于REST API Response的问题 #17
Comments
对于问题1: 需要在RunningInformation中对 “latitude”, "longitude"等加getter,然后为其加需要的annotation; |
请问在返回json response的时候,
flatten成
谢谢! |
对于问题1,我是直接在"latitude"前面加了个 |
对于问题1:我是这样做的,想要忽略哪个property |
我的处理方法是先建立一个JSONObject,然后按照作业要求的格式去设置它。 @RequestMapping(value = "/heartRateGreaterThan/{heartRate}", method = RequestMethod.GET)
public ResponseEntity<?> findByHeartRateGreaterThan(
@PathVariable Integer heartRate,
@RequestParam(name = "page", required = false, defaultValue = kDefaultPage) Integer page,
@RequestParam(name = "size", required = false, defaultValue = kDefaultItemPerPage) Integer size) {
Page<RunningInformation> rawResults = this.runningInformationService.findByHeartRateGreaterThan(heartRate, new PageRequest(page, size));
List<RunningInformation> content = rawResults.getContent();
// Transform RunningInformation to customized JSON objects
List<JSONObject> results = new ArrayList<JSONObject>();
for (RunningInformation item : content) {
JSONObject info = new JSONObject();
info.put("runningId", item.getRunningId());
info.put("totalRunningTime", item.getTotalRunningTIme());
info.put("heartRate", item.getHeartRate());
info.put("userId", item.getId());
info.put("userName", item.getUserInfo().getUsername());
info.put("userAddress", item.getUserInfo().getAddress());
info.put("healthWarningLevel", item.getHealthWarningLevel());
results.add(info);
}
return new ResponseEntity<List<JSONObject>>(results, HttpStatus.OK);
} |
在实现“返回结果按照healthWarningLevel从高到低进行排列,每页显示两个数据”这个要求时,我在postman中输入了相应的GET请求,得到了返回数据,但是返回的response中的内容非常冗长,有一些内容是作业中不需要显示的,如图所示
我想请教大家的是
自己也尝试加了一些@JsonIgnore,@JsonProperty之类的annotation,但是对这些不是很熟悉,所以一直研究不出来,感谢大家能帮忙看看这些问题,谢谢!
The text was updated successfully, but these errors were encountered: