- 导入包
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
- yml配置文件
spring:
datasource:
username: root
password:
url: jdbc:mysql://localhost:3306/user?characterEncoding=UTF-8&useUnicode=true&useSSL=false&serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
mybatis:
# 扫描mapper.xml
mapper-locations: classpath*:mapper/**/*.xml
#扫描别名
type-aliases-package: com.wei.entity
server:
servlet:
context-path: /springboot
- mybatis配置
mapper.xml配置文件以及mapper接口等
- 调用mapper接口