前提:
第一种情况:
1.1 mybatis的xml文件在resources/mapper路径下:
1.2 application.yml中mybatis相关配置如下:
mybatis:
mapper-locations: classpath*:resources/mapper/*.xml
于是程序启动一旦调用数据库查询就出现了如下问题:
ibatis.binding.BindingException: Invalid bound statement (not found)
意思是mapper.java找不到对应的mapper.xml
别人的回答都是抄,所有的回答基本全TM一个样!
解决问题还是要靠自己!
查看target:
你会发现编译后的mapper.xml路径中,resources不见了,所以,把
mybatis:
mapper-locations: classpath*:resources/mapper/*.xml
改为:
mybatis:
mapper-locations: classpath*:mapper/*.xml
问题解决!
解决这个问题最重要的途径是看你的target中有没有这个.xml文件或其路径对不对!
2. 另一种情况是,把mapper.xml和mapper.java都放到package中的情况:
在target里面没有看到mapper.xml文件,如下图:
正常情况下,应该是有mapper.xml文件才对,因此,发现在pom文件里面没有做响应的配置:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.yaml</include>
<include>**/*.json</include>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.woff</include>
<include>**/*.woff2</include>
<include>**/*.ttf</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<!-- 是否替换资源中的属性 -->
<filtering>false</filtering>
</resource>
</resources>
<build>
加上之后,将target文件夹删除,再编译一下module,就有了: