W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
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.
第一個(gè)注解,在Example
類上的,是@RestController
。這是一個(gè)被稱做“stereotype”的注解。它為閱讀代碼的人提供了提示,也為Spring提供了提示,這個(gè)類(class)扮演了一個(gè)特定的角色。在此情況下,我們的類是一個(gè)Web@Controller
, 因此Spring會(huì)在處理Web請(qǐng)求時(shí)考慮它。
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請(qǐng)求都應(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é)獲取更多細(xì)節(jié)。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: