@Controller vs @RestController

来源:互联网 发布:java时间轴代码 编辑:程序博客网 时间:2024/06/05 15:39

@Controller用于标记一个类,使用它标记的类就是一个SpringMVC Controller对象。

@RestController = @Controller + @ResponseBody

 @Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Controller @ResponseBody public @interface RestController

A convenience annotation that is itself annotated with @Controller and @ResponseBody.


Types that carry this annotation are treated as controllers where @RequestMapping methods assume @ResponseBody semantics by default.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RestController.html

https://stackoverflow.com/questions/25242321/difference-between-spring-controller-and-restcontroller-annotation

原创粉丝点击