jOOQ 代码生成器

jOOQ code generator

我使用了一个jOOQ程序代码来生成一个数据库,但现在我遇到了一些问题。在数据库中,我有table个A和B。第一次都生成了pojo,dao,interface等等。经过一段时间的开发,我发现tableA需要添加一些字段或者修改一些字段,所以我不得不重新编码,然后jOOQ代码生成器会覆盖现有代码,这使得我很伤心。当我用"exclude A"排除Atable的时候,发现只生成了TableA的数据,会删除TableB。我不知道如何处理这个问题。我的代码生成器如下:

public class JooqCodegen {

    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration()
                .withJdbc(new Jdbc()
                    .withDriver("com.mysql.jdbc.Driver")
                    .withUrl("jdbc:mysql://localhost:3306/microedudb")
                    .withUser("root")
                    .withPassword("root")
                )
                .withGenerator(
                        new Generator()
                        .withName("org.jooq.util.JavaGenerator")
                        .withGenerate(new Generate()
                            .withPojos(true)
                            .withImmutablePojos(true)
                            .withInterfaces(true)
                            .withDaos(true)
                            .withSpringAnnotations(true)
                            .withJavaTimeTypes(true)
                        )
                        .withDatabase(new Database()
                                .withName("org.jooq.util.mysql.MySQLDatabase")
                                //.withIncludes(".*")
                                .withExcludes("A")
                                .withDateAsTimestamp(true)
                                .withInputSchema("microedudb")
                        )
                        .withTarget(new Target()
                                .withPackageName("com.chunfytseng.microedu.jooq")
                                .withDirectory("src/main/java")
                        )
                        );
            GenerationTool.generate(configuration);
    }

}

jOOQ 代码生成器总是在生成代码时生成数据库模式的快照。这意味着任何未生成的 table(例如,由于 <exclude/> 配置)将从生成输出中删除。这很重要,因为您也可以删除 table,这会产生相同的效果。

so I'd have to code again and then jOOQ code generator will overwrite the existing code

切勿手动修改生成的代码。相反,每次在数据库中添加/删除列时,都应该重新生成整个架构。