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

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/" 
} 
主站蜘蛛池模板: 广州市| 兖州市| 措勤县| 炎陵县| 共和县| 金山区| 光山县| 东源县| 县级市| 哈巴河县| 通州市| 大田县| 东宁县| 莲花县| 临清市| 双鸭山市| 喀喇沁旗| 湖州市| 迁安市| 嘉黎县| 沂南县| 克山县| 阿克陶县| 宜章县| 吐鲁番市| 宾阳县| 衢州市| 焦作市| 精河县| 象州县| 长治县| 九江市| 仙桃市| 昌吉市| 木兰县| 巫溪县| 沙田区| 山阴县| 东光县| 晋江市| 武汉市|