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

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.

主站蜘蛛池模板: 新津县| 灵石县| 娄烦县| 龙州县| 闽侯县| 彩票| 平罗县| 峨眉山市| 梧州市| 堆龙德庆县| 阳西县| 石阡县| 同心县| 湟源县| 丹棱县| 邮箱| 萍乡市| 思南县| 大理市| 庆城县| 开鲁县| 乌兰浩特市| 开封市| 长葛市| 邓州市| 福清市| 和顺县| 承德县| 五家渠市| 梓潼县| 定陶县| 巴林左旗| 石城县| 凤翔县| 枣阳市| 永嘉县| 泗水县| 五常市| 嘉义市| 南乐县| 花莲市|