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

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.

主站蜘蛛池模板: 抚顺县| 万盛区| 子长县| 明溪县| 临漳县| 蓝田县| 东兴市| 桦南县| 揭西县| 新巴尔虎右旗| 莆田市| 苗栗市| 郑州市| 宽甸| 宜阳县| 泸定县| 潞城市| 金坛市| 京山县| 麻栗坡县| 阿鲁科尔沁旗| 沈丘县| 大英县| 斗六市| 明星| 杭锦旗| 密山市| 金门县| 漳平市| 驻马店市| 望江县| 新河县| 靖州| 冀州市| 固原市| 息烽县| 常德市| 察哈| 仁布县| 清新县| 厦门市|