SpringBoot-集成Mybatis

SpringBoot-集成Mybatis

SpringBoot-集成Mybatis

​ 在SpringBoot中对DAO层的解决方案提供了SpringDataJPA,但是我们在项目中使用MyBatis非常之多,所以我们这里介绍一下SpringBoot对MyBatis的整合。

​ SpringBoot中没有提供对MyBatis的默认支持,但是MyBatis官方提供了启动器,我们需要手动在pom文件中加入MyBatis启动器的依赖。

<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
</dependency>

​ 因为在SpringBoot中已经没有了MyBatis全局配置文件的概念,所以我们对MyBatis的配置都放在yml文件中进行。包括:mapper文件路径的指定、别名、驼峰转下换线等。。。

mybatis:
  mapper-locations: classpath:mapper/*Mapper.xml
  type-aliases-package: cn.ryafoo.core.bean
  configuration:
    map-underscore-to-camel-case: true

​ 最后,我们需要扫描Mapper接口,在SpringBoot的启动类上加上如下注解即可。

@MapperScan("cn.ryafoo.core.mapper")
posted @ 2019-11-23 11:14  张瑞丰  阅读(208)  评论(0编辑  收藏  举报