11.3.1 @RestController和@RequestMapping注解

2018-08-14 15:05 更新

The first annotation on our Example class is @RestController. This is known as a stereotype annotation. It provides hints for people reading the code and for Spring that the class plays a specific role. In this case, our class is a web @Controller, so Spring considers it when handling incoming web requests. 第一个注解,在Example类上的,是@RestController。这是一个被称做“stereotype”的注解。它为阅读代码的人提供了提示,也为Spring提供了提示,这个类(class)扮演了一个特定的角色。在此情况下,我们的类是一个Web@Controller, 因此Spring会在处理Web请求时考虑它。

The @RequestMapping annotation provides “routing” information. It tells Spring that any HTTP request with the / path should be mapped to the home method. The @RestController annotation tells Spring to render the resulting string directly back to the caller. @RequestMapping注解提供了“路由”信息。 它告诉Spring,任意带有/路径的HTTP请求都应该映射到home方法。@RestController注解告诉Spring直接将结果字符串返回给调用者。

提示

The @RestController and @RequestMapping annotations are Spring MVC annotations. (They are not specific to Spring Boot.) See the MVC section in the Spring Reference Documentation for more details.

@RestController@RequestMapping注解都是Spring MVC的注解。(它们不是SpringBoot特定的。)参见Spring参考文档中MVC章节获取更多细节。

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号