导入JDBC
其实都已经在创建springboot的时候导入了。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring‐boot‐starter‐jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql‐connector‐java</artifactId>
<scope>runtime</scope>
</dependency>
编写配置文件
spring:
datasource:
username: xxxx
password: xxx
url: jdbc:mysql://xxxx:3306/xxxx
driver‐class‐name: com.mysql.cj.jdbc.Driver
运行建表语句
默认将文件命名为:schema‐*.sql、data‐*.sql。
默认使用schema.sql,schema‐all.sql。
如果要自定义的话,可以在配置文件中加入:
spring:
datasource:
username: xxxx
password: xxx
url: jdbc:mysql://xxxx:3306/xxxx
driver‐class‐name: com.mysql.cj.jdbc.Driver
schema:
‐ classpath:department.sql //自己制定存放目录和文件名
参考文件
尚硅谷-Spring Boot核心技术-笔记