日常开发中,需要进行数据库设计建模,创建对应的表,可通过liquibase脚本自动生成数据库表,减少开发时间。
1.项目中pom文件引入liquibase的maven依赖
<!-- liquibase start -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<!-- liquibase end -->
2.resource目录下创建liquibase的changelog目录以及主配置文件
- resource目录下创建liquibase目录、二级目录changelog
- 添加主配置文件master.xml,指定path为changelog下sql配置文件,如下所示
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<includeAll path="liquibase/changelog/" relativeToChangelogFile="</