要操作和管理数据库,首先需要用 spring boot 管理数据源
步骤1:添加两个 maven 依赖
mysql mysql-connector-javaruntime org.springframework.boot spring-boot-starter-jdbc
步骤2:在 application.yml 中添加数据库连接信息
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=Asia/Shanghai username: root password: root
注意
com.mysql.cj.jdbc.Driver 是较新的驱动类,但一般要在 url 中添加 serverTimezone 参数
serverTimezone 不要设置为 UTC,



