1 回答

TA貢獻(xiàn)1794條經(jīng)驗 獲得超8個贊
您可以創(chuàng)建一個新的對象來序列化:
class ResponseWrapper {
private List<User> elements;
ResponseWrapper(List<User> elements) {
this.elements = elements;
}
}
ResponseWrapper然后在你的控制器方法中返回一個實例:
@RequestMapping(value = "/users", method = GET,produces = "application/xml")
@ResponseBody
public ResponseEntity<ResponseWrapper> getPartnersByDate(@RequestParam("type") String type, @RequestParam("id") String id) throws ParseException {
List<User> usersList = userService.getUsersByType(type);
ResponseWrapper wrapper = new ResponseWrapper(usersList);
return new ResponseEntity<ResponseWrapper>(wrapper, HttpStatus.OK);
}
添加回答
舉報