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

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.
主站蜘蛛池模板: 靖宇县| 盐城市| 牡丹江市| 河西区| 朝阳市| 郎溪县| 南和县| 马关县| 柳林县| 乐清市| 孝义市| 武宁县| 古浪县| 定兴县| 营山县| 上高县| 定西市| 灵丘县| 陆河县| 宝应县| 延安市| 嵊泗县| 玉林市| 阿勒泰市| 山阴县| 乡宁县| 河曲县| 潜江市| 浦北县| 沙洋县| 乐安县| 沁源县| 阿图什市| 德令哈市| 南和县| 西丰县| 辛集市| 伊通| 涞源县| 清新县| 舞阳县|