项目中创建mapper接口,编写xml文件sql语句,执行出现错误
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.atguigu.eduservice.mapper.EduCourseMapper.getPublishCourseInfo
开发中出现Invalid bound statement (not found)无外乎两种错误:
1.mapper中的方法名和xml中id名不一致
2.maven默认加载机制造成问题,maven加载的时候,把java文件夹里面.java类型文件进行编译,如果其他类型文件,不会加载,如xml
三种解决方式:
- 复制xml到target目录中
- 把xml文件放到resources目录中
- 通过配置实现(推荐):
1.pom.xml
<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
2.项目application.properties
#配置mapper xml文件的路径
mybatis-plus.mapper-locations=classpath:com/guli/edu/mapper/xml/*.xml