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

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.

主站蜘蛛池模板: 曲松县| 丘北县| 莆田市| 南乐县| 安陆市| 文昌市| 浦北县| 涟水县| 平遥县| 阳朔县| 安岳县| 弥勒县| 灵武市| 东乌| 锡林浩特市| 应城市| 靖远县| 普洱| 鄱阳县| 鲜城| 怀集县| 信阳市| 墨玉县| 巴彦淖尔市| 奎屯市| 永州市| 武宣县| 缙云县| 昭通市| 岳西县| 余江县| 桦甸市| 邛崃市| 汤原县| 嘉鱼县| 沙坪坝区| 北票市| 房产| 东丰县| 闽侯县| 庆云县|