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

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.
主站蜘蛛池模板: 卓尼县| 铁岭市| 平陆县| 巨野县| 安顺市| 邯郸市| 屯留县| 莎车县| 宁南县| 镇康县| 靖西县| 崇左市| 郯城县| 杨浦区| 清徐县| 雷波县| 莱西市| 临西县| 临西县| 拉孜县| 绥化市| 罗定市| 肥西县| 民丰县| 江西省| 大关县| 长泰县| 唐海县| 武平县| 靖西县| 曲靖市| 报价| 巴林右旗| 玉田县| 龙井市| 新田县| 靖边县| 唐海县| 晋州市| 宝应县| 周宁县|