1.导入数据库需要的依赖(引入了依赖,一定要刷新maven)
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
2.
3.配置yml文件
spring:
datasource:
url: jdbc:mysql://localhost:3306/qcby_db?useUnicode=true&characterEncoding=utf-8&serverTimezone=CTT
username: root
password: driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
mapper-locations: classpath:mapper/*.xml #对应mapper映射xml文件所在路径
type-aliases-package: com.xxxx.entity #对应实体类路径
4.切换成project模式,在resources下新建一个”mapper“的Directory
-----------------------------------Mybatis 整合完毕-----------------------------------------------
5.测试,数据库创建表
6.
7
8
9
10mapper和xml建立联系
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yglh.mapper.TestMapper">
</mapper>
11
12
13
14
15
16.service调用mapper层
17
18
19
20
21
------------------------------------------------------------------完成--------------------------
22.