- 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.
- Python程序設計教程(第2版)
- 騰訊iOS測試實踐
- Java程序設計與計算思維
- C語言從入門到精通(第4版)
- Mastering Ext JS
- Python算法從菜鳥到達人
- Asynchronous Android Programming(Second Edition)
- Working with Odoo
- Kotlin從基礎到實戰(zhàn)
- Python算法詳解
- Python程序設計與算法基礎教程(第2版)(微課版)
- Unity 2018 Augmented Reality Projects
- 計算機組裝與維護(第二版)
- Android智能手機APP界面設計實戰(zhàn)教程
- Offer來了:Java面試核心知識點精講(框架篇)