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

  • 相关阅读:
    sb世博
    seo 工具集锦
    各种Windows 操作系统中的 .NET Framework 支持
    httplib2模拟登陆
    python tips
    B2C电子商务能否通吃线上线下?
    复制镜像
    Scale Stack vs node.js vs Twisted vs Eventlet
    pool=eventlet.GreenPool(20)
    nginx最新部署
  • 原文地址:https://www.cnblogs.com/notably/p/14361520.html
Copyright © 2011-2022 走看看