- Spring Boot 2.0 Cookbook(Second Edition)
- Alex Antonov
- 159字
- 2021-06-24 19:24:39
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.
推薦閱讀
- 程序員修煉之道:從小工到專家
- DB29forLinux,UNIX,Windows數據庫管理認證指南
- Game Development with Swift
- Creating Mobile Apps with Sencha Touch 2
- 文本數據挖掘:基于R語言
- 大數據可視化
- 大數據:規劃、實施、運維
- Hadoop 3.x大數據開發實戰
- Hands-On Mathematics for Deep Learning
- PostgreSQL指南:內幕探索
- 數據庫技術及應用
- 深入理解InfluxDB:時序數據庫詳解與實踐
- Oracle高性能SQL引擎剖析:SQL優化與調優機制詳解
- Doris實時數倉實戰
- 大數據測試技術:數據采集、分析與測試實踐(在線實驗+在線自測)