一、作用

用于将配置路径下的*.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>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐