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

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 the pow() method 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 parameter required 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/" 
} 
主站蜘蛛池模板: 台湾省| 重庆市| 肃北| 兴义市| 铁岭县| 泰安市| 常宁市| 东乡| 拉萨市| 秦安县| 玉龙| 金阳县| 定襄县| 湘阴县| 中卫市| 泌阳县| 霞浦县| 来凤县| 红河县| 进贤县| 民和| 章丘市| 仲巴县| 苍南县| 横山县| 长白| 兴国县| 九江县| 嵊泗县| 武义县| 科尔| 若尔盖县| 太谷县| 德昌县| 多伦县| 同德县| 平谷区| 南溪县| 确山县| 凉山| 安远县|