spring-boot下mybatis.mapper-locations配置問題詳解


一、作用

用於將配置路徑下的*.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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM