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

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/" 
} 
主站蜘蛛池模板: 乌拉特前旗| 饶平县| 烟台市| 长泰县| 东丽区| 建瓯市| 嵊泗县| 木兰县| 漳平市| 平潭县| 宁海县| 台州市| 太仆寺旗| 延寿县| 白城市| 修水县| 平顶山市| 陇川县| 乐业县| 崇州市| 林芝县| 内丘县| 西安市| 博罗县| 德昌县| 南宁市| 岳西县| 康保县| 临西县| 新竹市| 读书| 张北县| 水城县| 夏津县| 石林| 昌黎县| 宁蒗| 昌平区| 宜章县| 库伦旗| 上虞市|