Skip to content
生如风生如风
主页
github icon
  • Mybatis的xml配置文件
    • 通常位置
      • 不想在resources中新建太深目录层级
        • 想要把xml文件和接口文件UserMapper2放在一起

        Mybatis—mapper配置文件xml位置

        author icon生如风calendar icon2022年11月10日category icon
        • Mybatis
        tag icon
        • Mybatis
        timer icon小于 1 分钟

        此页内容
        • Mybatis的xml配置文件
          • 通常位置
          • 不想在resources中新建太深目录层级
          • 想要把xml文件和接口文件UserMapper2放在一起

        第二次考完软考了,希望完成2022年下半年的一个目标,顺利通过考试。 记录mybatis接口xml配置文件的存放位置及相应方法

        # Mybatis的xml配置文件

        # 通常位置

        mybatis编写好mapper接口后,一般调用XXXmapper.xml的配置文件常放置在项目的resources下,并且与mapper接口的目录相关。 如:

        # 不想在resources中新建太深目录层级

        这种就需要在配置文件中指定localtion的位置

        mybatis.mapper-locations=classpath:mapper/*.xml
        
        1

        # 想要把xml文件和接口文件UserMapper2放在一起

        这种需要在pom.xml中build节点下指定需要包括的配置文件目录

        <resources>
            <resource>
                <!-- 打包带上 -->
                <directory>src/main/java</directory>
                <includes>
                    <!-- 任意目录下的*.xml-->
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13

        可以看看我的个人博客: 网站:http://www.fuzm.wang/open in new window

        —————————————————————————

        作为初学者,很多知识都没有掌握,见谅,如有错误请指出,以期进步,感谢!。后续有新的学习,继续补充上来。

        默认页脚
        Copyright © 2026 生如风