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請求都應(yīng)該映射到home方法。@RestController注解告訴Spring直接將結(jié)果字符串返回給調(diào)用者。

提示

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章節(jié)獲取更多細節(jié)。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號