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

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/" 
} 
主站蜘蛛池模板: 霞浦县| 徐州市| 同心县| 宣威市| 遂宁市| 临海市| 利辛县| 房山区| 九龙坡区| 永定县| 韶山市| 大关县| 当雄县| 社会| 延长县| 揭西县| 定边县| 沽源县| 邵阳市| 池州市| 昌图县| 英吉沙县| 天等县| 巫溪县| 桑日县| 万荣县| 抚顺市| 邵阳县| 鹤峰县| 瓮安县| 桦南县| 盐山县| 太保市| 甘洛县| 昆明市| 海宁市| 论坛| 扎鲁特旗| 大邑县| 平和县| 西城区|