org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题


即在mybatis中dao接口与mapper配置文件在做映射绑定的时候出现问题。

原因:接口与xml找不到,或者是找到了却匹配不到。有以下原因,需要逐条核查:

1、接口名与Mybatis的映射文件名一定要不一样;

2、XXXMapper.xml 文件 mapper 节点中 namespace 是否和 mapper 接口的所在包名一致;

3、XXXMapper.xml文件 mapper 节点下 id 是否在接口中有对应方法;

4、XXXMapper.xml文件 mapper 节点下所有 id,是否已全部包含了对应接口中的所有方法;

5、接口中返回值类型是List<XXX>,而select元素没有正确配置 ResultMap 或者 resultType ; 

6、XXXmapper.XML配置路径:

  如果在Resource下,则application.yml :mapper-locations: classpath:文件夹名/*.xml

  

 

 如果在java下其他位置,则application.yml:

mapper-locations: classpath*:com/lsk/xxxxx/mapperXml/*.xml 
注意 classpath后有“*”,并且包地址是“/”分割
另外,还需要在pom.xml增加build节点:
<build>
     <resources>
         <resource>
            <filtering>true</filtering>
            <directory>${basedir}/src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
         </resource>
         <resource>
            <directory>${basedir}/src/main/java</directory>
            <excludes>
               <exclude>**/*.xml</exclude>
            </excludes>
          </resource>
     </resources>
</build>

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM