1、pom.xml导入两个依赖:mysql-connector-java和spring-boot-starter-jdbc
代码键入:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
2、application.yml配置文件中新增数据库配置
代码键入:
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/demo?useSSl=false&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=Aisa/Shanghai
username: root
password: root