zoukankan      html  css  js  c++  java
  • Spring Boot+Mybatis mapper文件与mapper.xml分开放

    Mybatis与SpringBoot的集成:

    有关mybatis的maven依赖:

            
            <mybatis-spring-boot-starter.version>2.1.3</mybatis-spring-boot-starter.version>
            
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>${mybatis-spring-boot-starter.version}</version>
            </dependency>

    SpringBoot相关依赖:

           <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>

    application.yml配置:

    mybatis:
      #开启驼峰命名
      configuration:
        map-underscore-to-camel-case: true
      mapper-locations: classpath*:/mybatis-mapper/*Mapper.xml 

    上面mapper-locations配置只要能扫描定位到Mapper.xml 即可

    目录如下:

     如果mapper接口想与mapper.xml文件分开放的话,需要额外指定mapper接口扫描路径:

    在启动类上加上注解@MapperScan  指定mapper接口扫描路径,如:

    @SpringBootApplication
    @MapperScan(basePackages = {"com.dabai.dao"})
    public class ApiApplication {
        public static void main(String[] args) {
            SpringApplication.run(ApiApplication.class, args);
        }
    }

     这也mapper接口就能和mapper.xml分开放了

  • 相关阅读:
    drf3
    字典的操作方法
    列表的操作方法
    字符串的操作方法
    while循环和基本运算符
    初识数据类型
    USDT相关
    带团队
    CentOS7更改时区及同步网络时间
    mac胡刷新dns
  • 原文地址:https://www.cnblogs.com/notably/p/14361520.html
Copyright © 2011-2022 走看看