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

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.

主站蜘蛛池模板: 台中县| 定结县| 顺义区| 巧家县| 扎囊县| 洛阳市| 昌乐县| 海伦市| 襄城县| 昌乐县| 友谊县| 乡宁县| 昌平区| 应城市| 沛县| 永宁县| 宝坻区| 财经| 堆龙德庆县| 什邡市| 安溪县| 桦川县| 泽库县| 湖南省| 西和县| 鹤壁市| 华坪县| 乌鲁木齐县| 阿坝县| 象山县| 邵阳市| 黑河市| 青川县| 景洪市| 大宁县| 北票市| 高安市| 万盛区| 木里| 三江| 舟山市|