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

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.

主站蜘蛛池模板: 共和县| 简阳市| 淮滨县| 亳州市| 沅江市| 海盐县| 灌云县| 鄱阳县| 嵊泗县| 夏津县| 海门市| 黄石市| 紫金县| 婺源县| 满洲里市| 灵石县| 七台河市| 肥城市| 亳州市| 潜江市| 镇安县| 镇沅| 孝义市| 宜州市| 阿图什市| 崇阳县| 昌图县| 广宁县| 阿瓦提县| 双城市| 宜良县| 津南区| 陈巴尔虎旗| 开阳县| 奉节县| 启东市| 南召县| 芜湖市| 澄迈县| 安乡县| 石首市|