代码集成flyway
1、添加flyway依赖
<!--flyway 依赖--> <dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-core</artifactId> <version>5.2.4</version> </dependency>
2、注意flyway文件路径,必须在 db.migration下面
package db.migration; import org.flywaydb.core.api.migration.BaseJavaMigration; import org.flywaydb.core.api.migration.Context; import java.sql.PreparedStatement; /** * @PackageName: db.migration * @ClassName: V1_2__Another_user * @Description: * @author: * @date 2022/3/23 12:46 */ public class V1_2__Another_user extends BaseJavaMigration { public void migrate(Context context) throws Exception { try (PreparedStatement statement = context .getConnection() .prepareStatement("CREATE TABLE student (\n" + "\tid INT ( 4 ),\n" + "NAME VARCHAR ( 20 ),\n" + "sex CHAR ( 1 ));")) { statement.execute(); } } // public static void main(String[] args) { // Flyway flyway = Flyway.configure().dataSource("jdbc:mysql://localhost:3306/flyway_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8", // "root", // "123456").load(); // flyway.migrate(); // } }