使用 Springs MVC 返回 JSON 数据哪种方式更好,为什么?我应该发回 ResponseEntity 还是只发回对象?
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public User getDisplayDefault(ModelMap model)
{
return new User("realname", "john smith");
}
对比
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<User> getDisplayDefault(ModelMap model)
{
return new ResponseEntity<User>(new User("realname", "john smith"), HttpStatus.NOT_FOUND);
}