出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)的解决方法

(1) mapper接口类和mapper.xml是否在同一个包下,文件名称是否一致(仅后缀不同):经过实际检验,这个并不需要在同一个包下面,通常mapper.xml文件是存放在src/main/resources目录下,而mapper接口类是在src/main/java目录下面;名称是否相同也不重要,我的命名分贝为NumberDao.java和NumberMapper.xml,实际也可以运行成功 
(2)mapper.xml的namespace是否是对应接口类的全名(包括包名和类名):这个是必须要保证相同,需要进行检查,而且全类名最好通过复制,不要自己手动拼写,容易出错 
(3)mapper接口类的方法名是否与mapper.xml中sql标签的id相同:这个也需要进行检查,必须保证一致 
(4)mapper.xml文件中用resultMap,而不用resultType(当sql操作结果是List或其他复杂结果集时):我经过实践检验,我的查询结果是一个Integer的List集合,用resultMap反而报错,异常信息如下:

org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.lang.Integer
    at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:346)
    at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:290)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109)
    at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:788)
    at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:758)
    at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:753)
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.resolveMappedStatement(MapperMethod.java:247)
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:217)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
    at com.sun.proxy.$Proxy99.qryLockNumber(Unknown Source)
    at org.NumberRecovery.service.RecoveryService.qryLockNumber(RecoveryService.java:23)
    at org.NumberRecovery.service.RecoveryService$$FastClassBySpringCGLIB$$dc43da81.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
    at org.NumberRecovery.service.RecoveryService$$EnhancerBySpringCGLIB$$a9c68bd2.qryLockNumber(<generated>)
    at org.NumberRecovery.controller.RecoveryController.updateLockNumber(RecoveryController.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.Integer
    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:888)
    at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:640)
    at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:344)
    ... 36 common frames omitted

(5) 到target目录下看是否有mapper.xml文件生成(按照自己对mapper.xml文件的路径配置到target下classes目录下找),如果没有可以在pom.xml文件的<build></build>之间添加

<resources>
     <resource>
          <directory>src/main/resources</directory>
          <includes>
              <include>**/*.xml</include>
          </includes>
     </resource>
 </resources>

也可以再在<resources></resources>之间再添加一项

<resource>
    <directory>src/main/java</directory>
    <includes>
        <include>**/*.xml</include>
    </includes>
</resource>

使mapper.xml文件不论是放在src/main/resourcessrc/main/java下都可以被打包到classes目录下。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_270490096

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值