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 Controller。 -
@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屋!
查看全文