当前位置:网站首页>@What is the difference between controller and @restcontroller?

@What is the difference between controller and @restcontroller?

2022-06-23 07:54:00 Peihj2021

@Controller and @RestController The difference between ?

Official documents :
@RestController is a stereotype annotation that combines @ResponseBody and @Controller.
intend :
@RestController Annotation equivalent @ResponseBody + @Controller Combined action .

1) If you just use @RestController annotation Controller, be Controller The method in cannot be returned jsp page , Configured view parser InternalResourceViewResolver It doesn't work , What is returned is Return Contents of Li .

for example : I should have been there success.jsp Page , Then it is displayed success.


2) If necessary, return to the specified page , You need to use @Controller Coordinates with the view parser InternalResourceViewResolver Talent .
3) If you need to go back JSON,XML Or custom mediaType Content to page , You need to add to the corresponding method @ResponseBody annotation .
原网站

版权声明
本文为[Peihj2021]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230724054979.html