博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mybatis的mapper.xml使用parameterType使用的报错
阅读量:6480 次
发布时间:2019-06-23

本文共 11248 字,大约阅读时间需要 37 分钟。

错误在于一个写的get(Long id)的查询方法, 而在Mapper.xml中我定义了这个接收的参数的类型是int类型, 结果就报了如下的错误

1 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='id', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer  2     at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)  3     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)  4     at com.sun.proxy.$Proxy62.selectOne(Unknown Source)  5     at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)  6     at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87)  7     at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)  8     at com.sun.proxy.$Proxy101.get(Unknown Source)  9     at com.enuo.biz.server.impl.EnuoPermissionTypeServiceImpl.update(EnuoPermissionTypeServiceImpl.java:57) 10     at com.enuo.api.controller.account.company.permission.EnuoPermissionTypeController.update(EnuoPermissionTypeController.java:41) 11     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 12     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 13     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 14     at java.lang.reflect.Method.invoke(Method.java:498) 15     at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189) 16     at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) 17     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) 18     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892) 19     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) 20     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) 21     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) 22     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) 23     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) 24     at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908) 25     at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) 26     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) 27     at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) 28     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) 29     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 30     at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) 31     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 32     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 33     at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) 34     at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) 35     at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) 36     at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) 37     at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) 38     at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) 39     at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) 40     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 41     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 42     at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) 43     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 44     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 45     at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) 46     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 47     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 48     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 49     at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) 50     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 51     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 52     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 53     at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) 54     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 55     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 56     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 57     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) 58     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 59     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 60     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 61     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200) 62     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) 63     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) 64     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) 65     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) 66     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) 67     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) 68     at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) 69     at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 70     at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) 71     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) 72     at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 73     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 74     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 75     at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 76     at java.lang.Thread.run(Thread.java:748) 77 Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='id', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer 78     at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:89) 79     at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:94) 80     at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64) 81     at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:87) 82     at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) 83     at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) 84     at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) 85     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) 86     at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:143) 87     at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) 88     at com.sun.proxy.$Proxy128.query(Unknown Source) 89     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) 90     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) 91     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76) 92     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 93     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 94     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 95     at java.lang.reflect.Method.invoke(Method.java:498) 96     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) 97     ... 73 more 98 Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer 99     at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:71)100     at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:87)101     ... 91 more102 Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer103     at org.apache.ibatis.type.IntegerTypeHandler.setNonNullParameter(IntegerTypeHandler.java:26)104     at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:69)105     ... 92 more
报错信息

它说我的类型不匹配, 然后我看一下报错的提示, 直接定位到上面的地方, 只要把xml中定义的参数类型改成long就好了

转载于:https://www.cnblogs.com/Grace-is-enough/p/10757025.html

你可能感兴趣的文章
大数据在传统行业 落地之痛
查看>>
IBM想把“区块链”技术应用到金融服务以外
查看>>
海润光伏诉讼“威力”大 非公开发行终止也受影响
查看>>
旅游业或成服务机器人应用发展下一入口
查看>>
美国机构发布“智慧城市年度预测”,这几点值得关注
查看>>
Dropbox获6亿美元贷款额度 或年底IPO
查看>>
国内有哪些光伏逆变器厂家排进世界前十的?
查看>>
Facebook牵手微软:宣布将使用其office 365应用
查看>>
诺基亚携DOCOMO进行首次4.5G频段关键测试 助力5G技术开发
查看>>
联手绞杀NVIDIA?传Intel与AMD洽谈GPU授权
查看>>
网络安全研究人员发现新漏洞:或成另一个WannaCry
查看>>
为什么亚马逊要在物流中心屋顶安装太阳能电站?
查看>>
2017中国绿色数据中心发展论坛即将开幕
查看>>
转变有迹可循:企业DevOps部署意愿高涨
查看>>
Facebook正式推出360度全景视频服务
查看>>
神州信息中标量子通信“京沪干线”骨干网项目 迈出量子通信布局重要一步
查看>>
机房走线与服务器运行有何影响
查看>>
美国将试点利用通信技术改善交通状况
查看>>
iPhone7前景未知,Intel已赚走苹果100亿
查看>>
中国电信启动2016年PON设备集采:10G EPON端口小幅增长
查看>>