登录时@RequestBody报的错
Posted 青春不再见
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了登录时@RequestBody报的错相关的知识,希望对你有一定的参考价值。
昨天,我看了一下午,最后我们组长帮忙找出来的错,是个神坑!
关键是git服务器上不报错,可以正常访问。一到本地访问就500了
【{"success":false,"code":"500","message":"服务器繁忙,请稍后再试!","data":null,"count":0}】
原来的代码写的登录时候:
@Token(key = "telPhone")
@RequestMapping(value = "/login", method = RequestMethod.POST)
public Result login(HttpServletRequest request, @RequestBody MemberLoginDTO dto) {
logger.info("app登录处理参数:MemberLoginDTO = {} ", JSON.toJSONString(dto));
Result result = ResultUtil.getResult(RespCode.Code.REQUEST_DATA_ERROR);
if (StringUtils.isBlank(dto.getEquipmentId())) {
result.setMessage("[设备ID]不能为空");
return result;
}
// 2.登陆认证
result = memberService.memberLogin(dto);
logger.info("app登录返回数据:Result = {} ", JSON.toJSONString(result));
// 3.缓存用户信息
if (result.isSuccess()) {
result.setData(UserCacheUtil.addUser(dto.getTelPhone()));
}
return result;
}
控制台上报的错是:
09:48:41.721 [http-nio-10010-exec-3] ERROR com.phshopping.api.base.BaseErrorController - BaseErrorController Throwable :
org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public com.ph.shopping.common.util.result.Result com.phshopping.api.controller.regandlogin.LoginAndRegController.login(javax.servlet.http.HttpServletRequest,com.ph.shopping.facade.member.dto.MemberLoginDTO)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:154)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:128)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:158)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
09:48:41.722 [http-nio-10010-exec-3] ERROR com.phshopping.api.base.BaseErrorController - error message = app数据服务器未知异常 <> Required request body is missing: public com.ph.shopping.common.util.result.Result com.phshopping.api.controller.regandlogin.LoginAndRegController.login(javax.servlet.http.HttpServletRequest,com.ph.shopping.facade.member.dto.MemberLoginDTO)
09:48:41.722 [http-nio-10010-exec-3] ERROR com.phshopping.api.base.BaseErrorController - request error url : http://localhost:10010/api/login
当我把@RequestBody这个注解删除后:本地可以正常访问了
{"success":true,"code":"200","message":"操作成功","data":{"telPhone":"17778051803","memberName":null,"sex":null,"idCardNo":null,"isMarketing":2,"status":2,"headImage":null,"certification":1,"level":1,"id":27068,"token":"3C035091E40BFEDACB2EFB65DC727921",
"tokenToMobile":"B2331252766049858C806D97613C3205","equipmentId":"170976fa8aba22de0f0"},"count":0}
以上是关于登录时@RequestBody报的错的主要内容,如果未能解决你的问题,请参考以下文章
mybatis insert的时候中获取自动增长列的 时候报的错
我用的是 spring+struts2+jdbc代码执行到(代码在下面),就报错(报的错也在下面)