org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.by.mapper.UserMapper.insertUser
BindingException:绑定异常(字面意思)
(not found):没有找到
最后是一个方法名,也就是我们测试的方法
首先我们仔细查看名字(方法名、类名等),或者单词拼写有没有错误
反复检查,确认没有拼写不一致的错误之类的问题
后面通过查看target编译之后的目录发现,mapper中的xml目录不见了,这是由于maven加载时,java类型地 文件进行编译,非.java文件不会加载
编译后的文件:
源代码:
xml文件没有编译
- 解决方法:
- 赋值xml文件夹到target中
- 把xml文件夹放到resource中
- 通过配置实现(推荐)
一种pom文件
<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
一种application.propertities:在Spring Boot配置文件中添加配置
#配置mapper xml文件的路径
mybatis-plus.mapper-locations=classpath:com/guli/edu/mapper/xml/*.xml