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

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.

主站蜘蛛池模板: 沙雅县| 教育| 大兴区| 托克逊县| 屯昌县| 江孜县| 同江市| 马龙县| 库车县| 明星| 邵阳市| 天水市| 淄博市| 上杭县| 南丰县| 泾川县| 桓仁| 富平县| 应用必备| 象山县| 湘乡市| 汶上县| 上杭县| 东城区| 博湖县| 雅安市| 闽清县| 哈巴河县| 舒兰市| 庆城县| 南昌市| 军事| 安丘市| 贵德县| 新乡市| 关岭| 英德市| 游戏| 延津县| 中西区| 讷河市|