【问题标题】:jOOQ code generatorjOOQ 代码生成器
【发布时间】:2017-12-03 22:21:01
【问题描述】:

我使用了一个 jOOQ 程序代码来生成一个数据库,但现在我遇到了一些问题。在数据库中,我有表A和B。第一次都生成了pojo、dao、interface等。经过一段时间的开发,我发现A表需要添加一些字段或者修改一些字段,所以我不得不重新编码,然后jOOQ代码生成器会覆盖现有的代码,这让我很伤心。当我使用"exclude A" 和排除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);
    }

}

【问题讨论】:

    标签: java mysql jooq


    【解决方案1】:

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

    所以我必须再次编码,然后 jOOQ 代码生成器将覆盖现有代码

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

    【讨论】:

      猜你喜欢
      • 2020-12-23
      • 2014-09-09
      • 2017-08-13
      • 2020-01-23
      • 2016-01-15
      • 2014-03-06
      • 2017-12-08
      • 2016-06-12
      • 2016-11-22
      相关资源
      最近更新 更多