- 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.
推薦閱讀
- Redis使用手冊
- Hands-On Data Structures and Algorithms with Rust
- Spark快速大數據分析(第2版)
- Modern Programming: Object Oriented Programming and Best Practices
- Access 2007數據庫應用上機指導與練習
- Spark核心技術與高級應用
- Dependency Injection with AngularJS
- 智能數據分析:入門、實戰與平臺構建
- Oracle PL/SQL實例精解(原書第5版)
- 計算機應用基礎教程上機指導與習題集(微課版)
- 大數據精準挖掘
- 數字IC設計入門(微課視頻版)
- 新手學會計(2013-2014實戰升級版)
- Spring MVC Beginner’s Guide
- 改進的群智能算法及其應用