- 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.
- Boost.Asio C++ Network Programming(Second Edition)
- JavaScript前端開(kāi)發(fā)模塊化教程
- 劍指JVM:虛擬機(jī)實(shí)踐與性能調(diào)優(yōu)
- 樂(lè)學(xué)Web編程:網(wǎng)站制作不神秘
- Internet of Things with the Arduino Yún
- 鋒利的SQL(第2版)
- Java設(shè)計(jì)模式及實(shí)踐
- C語(yǔ)言實(shí)驗(yàn)指導(dǎo)及習(xí)題解析
- Nginx Lua開(kāi)發(fā)實(shí)戰(zhàn)
- jQuery炫酷應(yīng)用實(shí)例集錦
- Visual Studio 2015高級(jí)編程(第6版)
- Scratch3.0趣味編程動(dòng)手玩:比賽訓(xùn)練營(yíng)
- Node.js 12實(shí)戰(zhàn)
- OpenStack Networking Essentials
- 軟件工程與UML案例解析(第三版)