本文主要是介绍请求接口报错:java.lang.IllegalStateException: argument type mismatch,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- 一、场景
- 二、报错信息
- 三、控制器
- 四、接口调用
- 五、原因
- 六、解决
一、场景
1、调用后端接口报错
2、接口参数以Json方式传递
–
二、报错信息
java.lang.IllegalStateException: argument type mismatch
Controller [com.xxx.huarunshouzheng.controller.MallController]
Method [public java.lang.Object com.xxx.huarunshouzheng.controller.MallController.queryMyOrderList(com.alibaba.fastjson.JSONObject)] with argument values:[0] [type=org.springframework.validation.support.BindingAwareModelMap] [value={}] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:210)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1072)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)at javax.servlet.http.HttpServlet.service(HttpServlet.java:515)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)at javax.servlet.http.HttpServlet.service(HttpServlet.java:583)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:212)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:156)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:181)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:156)at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:181)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:156)at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:126)at org.springframework.boot.web.servlet.support.ErrorPageFilter.access$000(ErrorPageFilter.java:64)at org.springframework.boot.web.servlet.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:101)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:181)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:156)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:181)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:156)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:168)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:483)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:130)at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:679)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:617)at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:934)at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1698)at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Thread.java:750)
Caused by: java.lang.IllegalArgumentException: argument type mismatchat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)... 48 common frames omitted
三、控制器
@PostMapping("/queryMyOrderList")
public Object queryMyOrderList(JSONObject param) {Map<String, Object> retMap = new HashMap<String, Object>();retMap.put("code", 2);retMap.put("message", "请求数据返回失败!");logger.info("queryMyOrderList请求参数:param={}", param);try {// 省略代码逻辑......return result;} catch (Exception e) {logger.error("查询订单列表-接口对接出现异常:" + e.getMessage(), e);}return retMap;
}
四、接口调用
五、原因
控制器接口没有使用@RequestBody
声明参数以JSON方式接收参数,所以默认还是表单
六、解决
方法1、控制器添加@RequestBody
声明参数以JSON方式接收参数
@PostMapping("/queryMyOrderList")
// 参数添加@RequestBody注解
public Object queryMyOrderList(@RequestBody JSONObject param) {Map<String, Object> retMap = new HashMap<String, Object>();retMap.put("code", 2);retMap.put("message", "请求数据返回失败!");logger.info("queryMyOrderList请求参数:param={}", param);try {// 省略代码逻辑......return result;} catch (Exception e) {logger.error("查询订单列表-接口对接出现异常:" + e.getMessage(), e);}return retMap;
}
方法2、前端以表单的方式提交参数
这篇关于请求接口报错:java.lang.IllegalStateException: argument type mismatch的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!