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

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.
主站蜘蛛池模板: 房产| 福安市| 祥云县| 岐山县| 罗江县| 石林| 樟树市| 衡东县| 林州市| 安图县| 柘荣县| 三河市| 陵川县| 宾川县| 桦川县| 延寿县| 高陵县| 内江市| 平南县| 界首市| 北安市| 额尔古纳市| 灵宝市| 乌鲁木齐市| 盐池县| 华容县| 富平县| 门源| 光泽县| 邯郸县| 广灵县| 石门县| 工布江达县| 卓资县| 晋州市| 楚雄市| 大悟县| 新安县| 汾西县| 虹口区| 衡东县|