Spring 的@Controller 和@RestController的区别

时间:2023-12-05 13:52:08
@RestController Spring 4.0中新增的特性
@RestController 继承自 @Controller,相当于@ResponseBody + @Controller
1.只是使用@RestController时试图解析器不起作用,无法返回页面
例如:返回success.jsp 页面,返回的则是success字符串
2.如果要返回页面则使用@Controller
3.当使用@Controller时,要返回JSON,则在对应方法上添加@ResponseBody