有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java jOOQ代码生成器

我使用了一个jOOQ程序代码来生成数据库,但现在我遇到了一些问题。在数据库中,我有表A和表B。第一次都生成了pojo、dao、接口等。经过一段时间的开发,我发现表a需要添加一些字段或修改一些字段,所以我必须重新编码,然后jOOQ code generator将覆盖现有的代码,这让我非常难过。当我在排除表的同时使用“排除A”时,发现只生成了表A的数据,表B将被删除。我不知道如何处理这个问题。我的代码生成器如下所示:

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);
    }

}

共 (1) 个答案

  1. # 1 楼答案

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

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

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