springmvc 中@Controller和@RestController的区别

如题所述

4.0重要新改进@RestController注解继承自@Controller注解4.0前版本Spring MVC组件都使用@Controller标识前类控制器servlet

使用特性我发REST服务候需要使用@Controller专门@RestController

实现RESTful web services候response直通response body发送简化发Spring 4.0提供专门版本controller面我看看@RestController实现定义:
@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.
注解本身使用@Controller@ResponseBody注解使用注解类看作controller-使用@RequestMapping默认@ResponseBody注解
@ResponseBody – As of version 4.0 this annotation can also be added on the type level in which case is inherited and does not need to be added on the method level.
@ResponseBody加类级通继承级需要添加
-
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网