一、作用
用於將配置路徑下的*.xml文件加載到mybatis中
二、如何配置
springboot或者spring項目經常會引用其它項目,把其它項目的Jar包加進來,因為每個項目的包路徑不一樣,mapper.xml的路徑也不一樣,這個時候就需要引入多個路徑。
1. *.xml文件路徑在*resources包*下時,可根據路徑配置如下
方法一:只有一個路徑
mybatis.mapper-locations= classpath:mapper/*.xml
方法二:有多個路徑
mybatis.mapper-locations= classpath:mapper/*.xml,classpath:mapper/user*.xml
方法三:通配符 ** 表示任意級的目錄
mybatis.mapper-locations= classpath:**/*.xml
2. *.xml文件路徑在*java包*下時,不可使用mybatis.mapper-locations配置,可根據路徑配置如下
在pom.xml的<build>標簽中添加如下
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
重點:(轉載:https://blog.csdn.net/weixin_40160361/article/details/103876250)