前言:我们常常对数据库进行操作都需要通过mapper接口写相关方法,然后在相应的xml文件中写sql语句。在在线教育实践项目中发现了一个异常Invalid bound statement (not found): com.zzf.eduservice.mapper.EduCourseMapper.getPublishCourseInfo
以下有几种方法解决

检查报错的方法名是否错误

由于有可能是maven默认加载机制造成的问题,maven加载时候,把java文件进行编译,如果其他类型文件,则不会加载

复制xml到target目录中

把xml文件放到resource目录中

推荐使用:通过配置实现

1 pom.xml

在项目中的pom中配置如下节点

<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>

2 项目application.properties

在SpringBoot配置文件中添加配置

#配置mapper xml文件的路径
mybatis-plus.mapper-locations=classpath:com/guli/edu/mapper/xml/*.xml