Difference between @Controller and @RestController?

Official document:
@RestController is a stereotype annotation that combines @ResponseBody and @Controller.
Meaning:
@RestController annotation is equivalent to @ResponseBody + @Controller combined.

1) If you just use @RestController to annotate the Controller, the methods in the Controller cannot return to the jsp page, the configured view resolver InternalResourceViewResolver does not work, and the returned content is the content in Return.
For example, if it should go to the success.jsp page, it will display success.

2) If you need to return to the specified page, you need to use @Controller with the view resolver InternalResourceViewResolver.
3) If you need to return JSON, XML or custom mediaType content to the page, you need to add the @ResponseBody annotation to the corresponding method.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326484408&siteId=291194637