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類(lèi)上的,是@RestController。這是一個(gè)被稱(chēng)做“stereotype”的注解。它為閱讀代碼的人提供了提示,也為Spring提供了提示,這個(gè)類(lèi)(class)扮演了一個(gè)特定的角色。在此情況下,我們的類(lèi)是一個(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.
更多建議: