- 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.
- C程序設(shè)計(jì)簡明教程(第二版)
- Python快樂編程:人工智能深度學(xué)習(xí)基礎(chǔ)
- ReSharper Essentials
- 小創(chuàng)客玩轉(zhuǎn)圖形化編程
- 深入淺出Prometheus:原理、應(yīng)用、源碼與拓展詳解
- MATLAB應(yīng)用與實(shí)驗(yàn)教程
- JS全書:JavaScript Web前端開發(fā)指南
- 微信小程序開發(fā)與實(shí)戰(zhàn)(微課版)
- Distributed Computing in Java 9
- PHP+MySQL動(dòng)態(tài)網(wǎng)站開發(fā)從入門到精通(視頻教學(xué)版)
- Mastering Concurrency in Python
- Learning Jakarta Struts 1.2: a concise and practical tutorial
- INSTANT EaselJS Starter
- 前端Serverless:面向全棧的無服務(wù)器架構(gòu)實(shí)戰(zhàn)
- HTML5從入門到精通(第3版)