官术网_书友最值得收藏!

How it works...

The key to getting the service exposed to web requests is the @RestController annotation. This is yet another example of a meta-annotation or a convenience annotation, as the Spring documentation refers to it at times, which we have seen in previous recipes. In @RestController, two annotations are defined: @Controller and @ResponseBody. So we could just as easily annotate BookController, as follows:

@Controller 
@ResponseBody 
@RequestMapping("/books") 
public class BookController {...} 

Let's take a look at the following annotations from the preceding code snippet:

  • @Controller: This is a Spring stereotype annotation that is similar to @Bean and @Repository and declares the annotated class as an MVC
  • @ResponseBody: This is a Spring MVC annotation indicating that responses from the web-request-mapped methods constitute the entire content of the HTTP response body payload, which is typical for the RESTful applications
  • @RequestMapping: This is a Spring MVC annotation indicating that requests to /books/* URL will be routed to  this controller.
主站蜘蛛池模板: 玛多县| 张北县| 开原市| 桃源县| 宁德市| 苏尼特右旗| 明水县| 平顺县| 萨迦县| 漯河市| 文山县| 福建省| 临西县| 宿迁市| 重庆市| 清河县| 蓬莱市| 罗定市| 宁武县| 阳谷县| 手游| 梓潼县| 河东区| 九龙城区| 霍林郭勒市| 安化县| 荆州市| 项城市| 江陵县| 六安市| 黄浦区| 延庆县| 新野县| 祁门县| 江源县| 博客| 喀喇| 东城区| 宣汉县| 常宁市| 安丘市|