- Mastering Microservices with Java 9(Second Edition)
- Sourabh Sharma
- 169字
- 2021-07-02 21:54:45
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 annotation @RequestMapping of the URI (postfix of /calculation, for example, /calculation/sqrt/144), it would be mapped to 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 annotations @RequestParam and @PathVariable, respectively.
- Designing Machine Learning Systems with Python
- ASP.NET MVC4框架揭秘
- Delphi程序設(shè)計(jì)基礎(chǔ):教程、實(shí)驗(yàn)、習(xí)題
- C++面向?qū)ο蟪绦蛟O(shè)計(jì)(微課版)
- 實(shí)戰(zhàn)Java程序設(shè)計(jì)
- 精通搜索分析
- Unity 5 for Android Essentials
- Jenkins Continuous Integration Cookbook(Second Edition)
- NetBeans IDE 8 Cookbook
- 匯編語(yǔ)言編程基礎(chǔ):基于LoongArch
- PrimeFaces Blueprints
- Python網(wǎng)絡(luò)爬蟲技術(shù)與應(yīng)用
- C++ System Programming Cookbook
- HTML5 WebSocket權(quán)威指南
- Moodle 3.x Developer's Guide