2018-12-25
使用patch方式,使用@RequestParam注入参数,会获取不到参数,
查阅后发现http请求使用patch,后台Springmvc处理请求参数问题分析较具体
报错信息:
2018-12-25 15:13:34,980 http-nio-8080-exec-6 o.i.r.c.RestExceptionHandler ERROR Required String parameter 'number' is not present
org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'number' is not present
at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:204) ~[spring-web-5.0.7.jar:5.0.7.RELEASE]
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:112) ~[spring-web-5.0.7.jar:5.0.7.RELEASE]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124) ~[spring-web-5.0.7.jar:5.0.7.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) ~[spring-web-5.0.7.jar:5.0.7.RELEASE]
业务代码:
@RequestMapping(value = "/phone", method = RequestMethod.PATCH)
public RestStatus phone(@RequestParam String number, @LoggedInUser Employee loggedInEmployee) {
if (StringUtil.isBlank(number)) {
throw RestStatus.valueOf(RestStatus.CODE_FIELD_INVALID, "请提供待修改手机号");
}
if (!BusiUtil.validateMobileNo(number)) {
throw RestStatus.valueOf(RestStatus.CODE_FIELD_INVALID, "待修改手机号格式错误");
}
loggedInEmployee.setPhone(number);
employeeManager.save(loggedInEmployee);
return RestStatus.OK;
}
网友评论