mybatis的mapper.xml使用parameterType使用的报错

错误在于一个写的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 more
102 Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
103     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

你可能感兴趣的:(mybatis的mapper.xml使用parameterType使用的报错)