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

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.

主站蜘蛛池模板: 延安市| 永康市| 芦溪县| 遂川县| 都匀市| 闽清县| 肇东市| 彭泽县| 丹江口市| 望谟县| 普兰店市| 钟祥市| 兴义市| 太和县| 锡林浩特市| 汝阳县| 伊宁市| 和林格尔县| 扬中市| 聂荣县| 万安县| 城口县| 广平县| 克东县| 阜平县| 宝山区| 渝中区| 吉林市| 建水县| 桓仁| 余庆县| 瑞昌市| 永清县| 永川市| 大厂| 大荔县| 绍兴县| 沙雅县| 麻城市| 隆化县| 蚌埠市|