之前没搞明白@RestController和@Controller的区别.....所以用了@RestController, 导致跳不到视图.
两者的区别如下:
-
@Controller
is used to mark classes as Spring MVC Controller. -
@RestController
is a convenience annotation that does nothing more than adding the @Controller and @ResponseBody annotations
也就是: @RestController 等价于 @Controller 加上 @ResponseBody.
@ResponseBody 表示该方法的返回不会被解析为跳转, 而是直接写入http响应正文
原文: https://stackoverflow.com/questions/25242321/difference-between-spring-controller-and-restcontroller-annotation
@ResponseBody参考文档: http://blog.csdn.net/ff906317011/article/details/78552426
网友评论