Mybatis configures multiple ways of mapper-locations location

Method 1 puts the xml file and the mapper class together.

insert image description here

yml configuration

mybatis:
  config-location: classpath:mybatis-config.xml
  mapper-locations: classpath:com/example/pgsqldemo/mybatis/dao/xml/*.xml
#  mapper-locations: classpath:static/mybatis/mapper/*.xml

pom.xml configuration

<build>
    <resources>
        <!-- 扫描src/main/java下所有xx.xml文件 -->
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <!-- 扫描resources下所有资源 -->
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
</build>

Method 2: resources creates a folder with the same name as the Mapper interface to store the Mapper.xml file (mybatis default method)

insert image description here

yml configuration

mybatis:
  config-location: classpath:mybatis-config.xml

Method 3 Create a custom folder in the resources directory for storage

insert image description here

yml configuration

mybatis:
  config-location: classpath:mybatis-config.xml
  mapper-locations: classpath:/mapper/*.xml

Guess you like

Origin blog.csdn.net/riding_horse/article/details/130365135