The difference between the role of @RestController and @Controller

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 @RestCotrollerto simplify the writing

  @RestCotroller source

···

  From the above we can clearly see the source code@RestController = @Controller + @ResponseBody

Use @Controllermodified class, we may need to return various data required (using the json (method @ResponseBod), ModelAndView, static pages), and the use of RestControllerthe modified class, and returns the results will be parsed into json string, suitable for all method returns the data values are json

Guess you like

Origin www.cnblogs.com/chcha1/p/11274573.html