- 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.
推薦閱讀
- 計算機組成原理與接口技術:基于MIPS架構實驗教程(第2版)
- Building Computer Vision Projects with OpenCV 4 and C++
- 云計算環境下的信息資源集成與服務
- 業務數據分析:五招破解業務難題
- Live Longer with AI
- iOS and OS X Network Programming Cookbook
- Spark核心技術與高級應用
- 城市計算
- Starling Game Development Essentials
- 云數據中心網絡與SDN:技術架構與實現
- Internet of Things with Python
- 數據庫原理與設計實驗教程(MySQL版)
- AndEngine for Android Game Development Cookbook
- 數據中臺實戰:手把手教你搭建數據中臺
- Cognitive Computing with IBM Watson