控制层方法不加@ResponseBody 怎么返回的json?
控制层方法不加@ResponseBody 怎么返回的json?
控制层方法不加@ResponseBody 怎么返回的json?
2019-08-23
控制层方法不加@ResponseBody返回的json的方法:
1、使用@ResponseBody表示直接在response中加入一实体(如Json格式)并直接返回
@RequestMapping(value = "/{courseId}",method = RequestMethod.GET)
public @ResponseBody Course getCourseInJson(@PathVariable Integer courseId) {
Course course = courseService.getCoursebyId(courseId);
return course;
}
2、返回Json格式数据方法2:
@RequestMapping(value = "/jsonType/{courseId}",method = RequestMethod.GET)
public ResponseEntity<Course> getCourseInJson2(@PathVariable Integer courseId) {
Course course = courseService.getCoursebyId(courseId);
return new ResponseEntity<>(course, HttpStatus.OK);
}
举报