org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题,
即在mybatis中dao层与mapper层文件在做映射绑定的时候,无法一一对应。接口找不到xml。
解决方案:
第一种:在你的pom.xml的build中,添加配置项.
<resourceS>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>application.yml</include>
</includes>
<filtering>true</filtering>
<targetPath>BOOT-INF/classes</targetPath>
</resource>
</resourceS>
同时,需要在resources文件夹下的application.yml文件中,新增以下信息。
没有application.yml就自己新建一个,有application.perproties也行,只不过二者配置属性的方式不同,Springboot读取二者的优先级不同而已
mybatis:
mapper-locations: classpath*:com/example/demo/**/*apper.xml
配置mapper-locations的时候,首先应该保证你的Mapper层的xml文件是以apper.xml文件结尾的。示例:StudentMapper.xml
如果你的Mapper层的xml文件的命名规范是以Dao结尾:StudentDao.xml,那么就设置如下:
mybatis:
mapper-locations: classpath*:com/example/demo/**/*Dao.xml
当然原理上你也可以设置成
mybatis:
mapper-locations: classpath*:com/example/demo/**/*.xml
但是如果你的项目中xml文件过多,还是建议使用apper.xml结尾的设置方式