Upe*_*pen 5 java spring spring-mvc spring-restcontroller
I have a spring mvc controller which is serving web service requests with multiple request parameters. All the parameters are marked required = false. Still if in the request a parameter is not available,
@RequestMapping(value = "/service/deployNew", method = RequestMethod.POST)
@ResponseBody public ResponseEntity<DeploymentId> deploy(HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false, value = "abc") String abc, @RequestParam(required = false, value = "xyz") String xyz, @RequestParam(required = false, value = "uvw") String uvw,) throws Exception;
Run Code Online (Sandbox Code Playgroud)
I see the error
required string parameter 'param' is not present
Run Code Online (Sandbox Code Playgroud)
If I give a blank value to the param, everything works fine as below. Parameters abc and xyz has a blank value, but still I am passing it.
curl -i -X POST -H Accept:application/json "http://localhost:8080/Test/service/deploy.do?abc=&xyz=&uvw=somevalue"
Run Code Online (Sandbox Code Playgroud)
If I remove any of the above param it will throw the error.
curl -i -X POST -H Accept:application/json "http://localhost:8080/Test/service/deploy.do?uvw=somevalue"
Run Code Online (Sandbox Code Playgroud)
My service is being used by multiple clients with a single endpoint which caused some parameters to be present at times. I need to handle all the scenarios. Any idea?
小智 -2
尝试使用默认值
@RequestParam(required = false, defaultValue = "somevalue")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8474 次 |
| 最近记录: |