web项目中添加MySQL驱动

时间:2024-08-04 18:07:44

1.我这里采用yml文件来配置,yml有配置层次清晰,方便操作的好处:
将application.properties后缀改成yml,即配置文件变成application.yml
我的application.yml如下:

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1/dataname
    username: root
    password: root

2.要使用数据库要添加mysql依赖以及spring提供的jpa依赖
1) <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
/dependency>

2) <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>