Required request parameter ‘token‘ for method parameter type xxxx is not present 解决方式
昨天系统有个绑定手机号的功能接口,绑定提交一直报错不好使,报错如下:
-
GlobalExceptionHandler.exceptionHandler:message:Required request parameter 'token' for method parameter type String is not present, stackTrace:
-
[org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValueInternal(RequestParamMethodArgumentResolver.java:218),
-
org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:193),
-
org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:114),
-
org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121),
-
org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179),
-
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146),
-
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117),
-
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895),
-
......
这个报错很明显是参数传递时出现问题,看接口代码:
-
-
-
public Map<?, ?> bindingMobile( UserVo userInfo, String token) {
-
// 内容省略
-
}
我看这个参数写法,一阵头大,POST请求,获取参数怎么还用 @RequestParam 注解,这匹配不了啊。我这边查看了请求,发现token参数是在请求头中,于是修改了接口参数:
-
-
-
public Map<?, ?> bindingMobile( UserVo userInfo, HttpServletRequest request) {
-
-
// 获取token
-
String token = request.getHeader("token");
-
-
// 下面内容省略
-
}
上面修改后参数获取就没问题了,接口功能也好使了。
网上有个博主列出了请求类型和参数的对应表,我觉得挺好的,引用一下:
注解 | 支持的类型 | 支持的请求类型 | 支持的Content-Type | 请求示例 |
---|---|---|---|---|
@PathVariable | url | GET | 所有 | /test/{id} |
@RequestParam | url | GET | 所有 | /test?id=1 |
@RequestBody | Body | POST/PUT/DELETE/PATCH | json | {“id”:1} |
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhfhaiag
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
excel下划线不显示怎么办
PHP中文网 06-23 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
photoshop蒙版画笔没反应怎么办
PHP中文网 06-24