1 - In springboot
, the @RestController
equivalent ; 2 - that is, in class, if you want to return or page, can not be used , use only ; 3 - if the returns or data may be written in two: @Controller + @ResponseBody
Controller
jsp
html
@RestController
@Controller
json
xml
1. @RestController annotation data can then directly return json; before liberation Note 2. @Controller class and if the class requires a method to return json data, before the need to add annotations @ResponseBody the method;
Example]:
@RestController public class BookController { @Autowired private BookRepository bookRepository; /** * 返回所有书籍的信息 * @return */ @RequestMapping(value = "/books", method = RequestMethod.GET) public List<Book> bookList(){ return bookRepository.findAll(); } }
@Controller public class BookController2 { @Autowired private BookRepository bookRepository; /** * 返回所有书籍的信息 * @return */ @RequestMapping(value = "/books", method = RequestMethod.GET) @ResponseBody public List<Book> bookList(){ return bookRepository.findAll(); } }