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

The @RequestParam annotation

@RequestParam is responsible for binding the query parameter to the parameter of the controller's method. For example, the QueryParam base and exponent are bound to parameters b and e of method pow() of CalculationController respectively. Both of the query parameters of the pow() method are required since we are not using any default value for them. Default values for query parameters could be set using the defaultValue property of @RequestParam, for example, @RequestParam(value="base", defaultValue="2"). Here, if the user does not pass the query parameter base, then the default value 2 would be used for the base.

If no defaultValue is defined, and the user doesn't provide the request parameter, then RestController returns the HTTP status code 400 with the message Required String parameter 'base' is not present. It always uses the reference of the first required parameter if more than one of the request parameters is missing:

{ 
  "timestamp": 1464678493402, 
  "status": 400, 
  "error": "Bad Request", 
  "exception": "org.springframework.web.bind.MissingServletRequestParameterException", 
  "message": "Required String parameter 'base' is not present", 
  "path": "/calculation/power/" 
} 
主站蜘蛛池模板: 乐东| 和顺县| 福安市| 石楼县| 巴彦淖尔市| 卢氏县| 徐水县| 城步| 南溪县| 白山市| 改则县| 伊川县| 廊坊市| 界首市| 昭平县| 元朗区| 文安县| 仁化县| 嘉祥县| 株洲县| 盐边县| 昌江| 邢台市| 慈溪市| 鄱阳县| 道孚县| 盐亭县| 水城县| 石首市| 巴东县| 九江县| 定远县| 芜湖市| 商南县| 公安县| 永新县| 额济纳旗| 舒兰市| 淳安县| 库尔勒市| 淳化县|