@Controller与RestController之间的区别
@RestController注解==>@Controller+@ResponseBody
1、如果使用RestController注解Controller,则Controller不能跳转到jsp,html页面。视图解析器InternalResourceViewResolver不起作用,只会返回Retrun的内容。
2、如果需要返回页面,则需要使用@Controller配合视图解析器InternalResourceViewResolver使用
3、如果需要返回JSON,XML或自定义mediaType内容到页面,则需要在对应的方法上加上@ResponseBody注解。
例子
pom.xml导入依赖
THML页面
Cotrroller层代码
1、如果使用@RestController,无法跳转到html页面,只会返回return的内容
结果:
如果使用@Controller注解,则会跳转到html页面
结果: