官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 寿光市| 黎平县| 特克斯县| 衡东县| 米易县| 黑水县| 永仁县| 营山县| 利津县| 靖江市| 偏关县| 沙田区| 乐业县| 松阳县| 金山区| 汪清县| 华亭县| 克拉玛依市| 湘西| 息烽县| 金湖县| 红原县| 兴山县| 汾西县| 田林县| 内丘县| 阳原县| 德化县| 兰州市| 治多县| 乡宁县| 兴和县| 张掖市| 重庆市| 德惠市| 鄢陵县| 珠海市| 德清县| 马山县| 米林县| 馆陶县|