- 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.
推薦閱讀
- Python數據分析與挖掘實戰
- 計算機信息技術基礎實驗與習題
- Lean Mobile App Development
- OracleDBA實戰攻略:運維管理、診斷優化、高可用與最佳實踐
- 數據庫原理與應用(Oracle版)
- 智能數據時代:企業大數據戰略與實戰
- 辦公應用與計算思維案例教程
- SQL Server深入詳解
- Python數據分析從小白到專家
- 機器學習:實用案例解析
- 改進的群智能算法及其應用
- 數據中心經營之道
- 大數據測試技術:數據采集、分析與測試實踐(在線實驗+在線自測)
- Visual Studio 2012 and .NET 4.5 Expert Development Cookbook
- NoSQL數據庫原理(第2版·微課版)