解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题,即在mybatis中dao接口与mapper配置文件在做映射绑定的时候出现问题,简单说,就是接口与xml要么是找不到,要么是找到了却匹配不到。
常见错误
- Mapper.xml文件中的namespace 路径错误 导致映射不到
- Mapper.xml中定义的每个statement的id错误 导致映射不到
- parameterType 路径错误 导致映射不到
- resultType的类型相同 路径错误 导致映射不到
以上都不是的话,可能是*.xml没有被处理到。
在系统文件夹查看 项目里的编译文件 target 中是否有映射的xml文件。
没有 ?
解决:maven 问题 pom 中 加上
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</build>
然后 clean 项目
继续报错:
将映射的xml 文件放到映射的Java文件夹内,不报错。就说明 mapper 文件夹没被处理
解决:在 application.yml 加上
mybatis:
mapper-locations: xx/xxxx/xx/mapping/*.xml
type-aliases-package: xx/xxxx/xxx/entity