In springMvc to be used on the controller layer belongs to the class indicated by the class @Controller control layer, there are several forms of data in the controller layer often returns:
Page: static pages
ModelAndView: return to the page and the corresponding data
json string: If a class is designed to return json string, then the class can be used @Controller + @ResponseBody
, it is also possible @RestCotroller
to simplify the writing
@RestCotroller source
···
From the above we can clearly see the source code@RestController = @Controller + @ResponseBody
Use @Controller
modified class, we may need to return various data required (using the json (method @ResponseBod), ModelAndView, static pages), and the use of RestController
the modified class, and returns the results will be parsed into json string, suitable for all method returns the data values are json