我使用了 jOOQ 程序代码来生成数据库,但现在遇到了一些问题。在数据库中,我有表A和B。第一次都生成了pojo,dao,接口(interface)等。经过一段时间的开发,我发现A表需要增加一些字段或者修改一些字段,所以我必须重新编码,然后jOOQ代码生成器会覆盖现有的代码,这让我很伤心。当我使用“排除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);
}
}
最佳答案
jOOQ 代码生成器始终在生成代码时生成数据库模式的快照。这意味着任何未生成的表(例如,由于 <exclude/>
配置)将从生成输出中删除。这很重要,因为您也可以删除该表,这会产生相同的效果。
so I'd have to code again and then jOOQ code generator will overwrite the existing code
您永远不应该手动修改生成的代码。相反,每次在数据库中添加/删除列时,都应该重新生成整个架构。
关于java - jOOQ代码生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44838285/