RestController与Controller的区别
【推荐阅读】微服务还能火多久?>>> Spring 4.0 重要的一个新的改进是增加了 @RestController 注解,它继承自 @Controller 注解。4.0之前的版本,Spring MVC 的组件都使用 @Controller 来标识当前类是一个控制器servlet。 使用这个特性,我们可以在开发REST服务的时候可以不使用 @Controller+@ResponseBody 的方式而只使用 @RestController。 当你使用实现一个 RESTful web services 的时候,response 将一直通过 response body 发送。为了简化开发,Spring 4.0提供了一个专门版本的controller:@RestController。 下面我们来看看@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