springboot+mybatis报错Invalid bound statement (not found)

Posted 少年曾续缘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot+mybatis报错Invalid bound statement (not found)相关的知识,希望对你有一定的参考价值。

今天做项目时报了一个错提示说Invalid bound statement (not found),也就是说mapper接口绑定.xml文件出错了,找不到指定的sql;原因是程序没有把.xml文件编译到classes路径下,这时需要在pom.xml文件的<build>标签中加入下面的配置解决
<resources>
<!-- maven项目中src源代码下的xml等资源文件编译进classes文件夹,
注意:如果没有这个,它会自动搜索resources下是否有mapper.xml文件,
如果没有就会报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pet.mapper.PetMapper.selectByPrimaryKey-->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>

<!--将resources目录下的配置文件编译进classes文件 -->
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>

以上是关于springboot+mybatis报错Invalid bound statement (not found)的主要内容,如果未能解决你的问题,请参考以下文章

springboot集成报错,想要集成tk.mybatis报错,反射方法异常

SpringBoot3整合MyBatis报错:Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required

SpringBoot 整合Mybatis报错(Invalid bound statement (not found))

SpringBoot整合Mybatis报错:Cause: java.lang.UnsupportedOperationException]

eclipse环境下的springboot框架+mybatis访问MySQL报错空指针

SpringBoot 整合Mybatis报错解决(Failed to determine a suitable driver class)