pom
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
yaml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ruiwen?serverTimezone=GMT
username: root
password: root
# mybatis相关
mybatis:
mapper-locations: classpath*:AdminUserMapper/*.xml
config-location: classpath:config/mybatis-config.xml
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<package name="com.mybatis.domain"/>
</typeAliases>
<!--<mappers>-->
<!--<mapper resource="com/ruyi/mybatis/mapper/AdminUserMapper.xml"/>-->
<!--</mappers>-->
</configuration>
config-location:指定 MyBatis 主配置文件的位置
mapper-locations:指定 mapper 文件的位置。如果在项目中你的 mapper 文件是按目录来放置,那么对应的配置就变成:mapper-locations: classpath:mapper/*/*.xml
springboot会自动加载spring.datasource.*相关配置
在启动类中添加对mapper包扫描@MapperScan或在dao添加@Mapper
大神文章:https://www.hifreud.com/2017/07/11/spring-boot-22-integrate-with-mybatis/