springmvc 添加@ResponseBody

时间:2021-03-02 15:18:19
1.添加ResponseBody之后的话 返回字符串的时候 就是一个字符串、
@RequestMapping(value = "/{bookId}/detail.do",method = RequestMethod.GET)
@ResponseBody
private String detail(@PathVariable("bookId")Long bookId ,Model model){
 
if(bookId == null){
 
return "redirect:/book/list";
}
Book book = bookService.getById(bookId);
 
if(book == null){
return "forward:/book/list";
}
 
model.addAttribute("detail",book);
 
return "detail";
}
 
2. 如果不添加ResponseBody的话 model对象才能绑定到jsp的页面,就会返回一个对象