spring_reference/II. Getting started/11.3.1. The @RestController...

9 lines
889 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 11.3.1. @RestController和@RequestMapping注解
我们的`Example`类上使用的第一个注解是`@RestController`。这被称为一个构造型stereotype注解。它为阅读代码的人们提供建议。对于Spring该类扮演了一个特殊角色。在本示例中我们的类是一个web `@Controller`所以当处理进来的web请求时Spring会询问它。
`@RequestMapping`注解提供路由信息。它告诉Spring任何来自"/"路径的HTTP请求都应该被映射到`home`方法。`@RestController`注解告诉Spring以字符串的形式渲染结果并直接返回给调用者。
**注**`@RestController`和`@RequestMapping`注解是Spring MVC注解它们不是Spring Boot的特定部分。具体查看Spring参考文档的[MVC章节](http://docs.spring.io/spring/docs/4.1.5.RELEASE/spring-framework-reference/htmlsingle#mvc)。