spring @Controller 和 @RestController 注解的区别 [英] Difference between spring @Controller and @RestController annotation
本文介绍了spring @Controller 和 @RestController 注解的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
spring @Controller
和 @RestController
注解的区别.
Difference between spring @Controller
and @RestController
annotation.
@Controller
注释是否可以同时用于 Web MVC 和 REST 应用程序?
如果是,如何区分是Web MVC还是REST应用.
Can @Controller
annotation be used for both Web MVC and REST applications?
If yes, how can we differentiate if it is Web MVC or REST application.
推荐答案
@Controller
用于将类标记为 Spring MVC 控制器.@RestController
是一个方便的注解,只不过是添加了@Controller
和@ResponseBody
注释(参见:Javadoc)@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 (see: Javadoc)
所以下面的两个控制器定义应该是一样的
So the following two controller definitions should do the same
@Controller
@ResponseBody
public class MyController { }
@RestController
public class MyRestController { }
这篇关于spring @Controller 和 @RestController 注解的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文