• 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分开放了

  • 相关阅读:
    ORACLE修改列名与列类型
    ORACLE的显式游标与隐式游标
    ORACLE 异常错误处理
    ORACLE的强制索引
    看懂ORACLE执行计划
    ORACLE建立物化视图
    普通视图和物化视图的区别
    ORACLE 中 TRANSLATE的用法
    随手小代码——归并排序
    随手小代码——选择算法排序
  • 原文地址:https://www.cnblogs.com/notably/p/14361520.html
Copyright © 2020-2023  润新知