- Mastering Microservices with Java
- Sourabh Sharma
- 171字
- 2021-07-02 13:03:32
The @RequestMapping annotation
The @RequestMapping annotation is used at class level to map the /calculation URI to the CalculationController class; that is, it ensures that the HTTP request to /calculation is mapped to the CalculationController class. Based on the path defined using the @RequestMapping annotation of the URI (postfix of /calculation, for example, /calculation/sqrt/144), it would be mapped to the respective methods. Here, the request mapping, /calculation/sqrt, is mapped to the sqrt() method, and /calculation/power is mapped to the pow() method.
You might have also observed that we have not defined what request method (GET/POST/PUT, and so on) these methods would use. The @RequestMapping annotation maps all the HTTP request methods by default. You could use specific methods by using the method property of RequestMapping. For example, you could write a @RequestMethod annotation in the following way to use the POST method:
@RequestMapping(value = "/power", method = POST)
For passing the parameters along the way, the sample demonstrates both request parameters and path parameters using the @RequestParam and @PathVariable annotations, respectively.
- Spring Cloud Alibaba核心技術與實戰案例
- Advanced Machine Learning with Python
- C語言程序設計(第2 版)
- AutoCAD VBA參數化繪圖程序開發與實戰編碼
- SQL Server 2016數據庫應用與開發習題解答與上機指導
- Elasticsearch for Hadoop
- Scientific Computing with Scala
- Mastering Web Application Development with AngularJS
- 詳解MATLAB圖形繪制技術
- Instant Zurb Foundation 4
- Java 9 Programming By Example
- 從零開始學Selenium自動化測試:基于Python:視頻教學版
- C#面向對象程序設計(第2版)
- AI自動化測試:技術原理、平臺搭建與工程實踐
- Android智能手機APP界面設計實戰教程