创建一个SpringBoot项目(连接数据库)
新建项目
根据自己的情况选依赖
删除不用的文件
加载maven依赖
配置数据库 别忘了修改自己的用户名和密码、数据库的名称(注意格式)
server:port: 9090spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverusername: 用户名password: 用户密码url: jdbc:mysql://localhost:3306/你的数据库名称?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8&allowPublicKeyRetrieval=true
此时要注意你的数据库是可以正常连接的
# 命令行测试
mysql -u root -p -h localhost -P 3306
期间出现了如下问题,这是因为少了依赖
<dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope>
</dependency>
启动项目