程序化配置的内存编译
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
各种代码生成配置元素允许通过外部类进行编程配置。这允许对代码生成行为进行更细粒度的控制。示例包括
以上示例都允许为相关对象的内存编译指定内联代码。例如,在定义 GeneratorStrategy 时
XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
<generator>
<strategy>
<name>com.example.AsInDatabaseStrategy</name>
<java>package com.example;
import org.jooq.codegen.DefaultGeneratorStrategy;
public class AsInDatabaseStrategy extends DefaultGeneratorStrategy {
...
}</java>
</strategy>
</generator>
</configuration>
有关更多详细信息,请参阅配置 XSD、独立代码生成和maven 代码生成。
new org.jooq.meta.jaxb.Configuration()
.withGenerator(new Generator()
.withStrategy(new Strategy()
.withName("com.example.AsInDatabaseStrategy")
.withJava("""package com.example;
import org.jooq.codegen.DefaultGeneratorStrategy;
public class AsInDatabaseStrategy extends DefaultGeneratorStrategy {
...
}""")
)
)
import org.jooq.meta.jaxb.*
configuration {
generator {
strategy {
name = "com.example.AsInDatabaseStrategy"
java = """package com.example;
import org.jooq.codegen.DefaultGeneratorStrategy;
public class AsInDatabaseStrategy extends DefaultGeneratorStrategy {
...
}"""
}
}
}
有关更多详细信息,请参阅配置 XSD和gradle 代码生成。
configuration {
generator {
strategy {
name = "com.example.AsInDatabaseStrategy"
java = """package com.example;
import org.jooq.codegen.DefaultGeneratorStrategy;
public class AsInDatabaseStrategy extends DefaultGeneratorStrategy {
...
}"""
}
}
}
有关更多详细信息,请参阅配置 XSD和gradle 代码生成。
// The jOOQ-codegen-gradle plugin has been introduced in version 3.19. // Please use the official plugin instead of the third party plugin that was recommended before.
name必须与GeneratorStrategy的完全限定类名匹配。
确保您的自定义实现的依赖项作为代码生成依赖项可供代码生成器使用
反馈
您对此页面有任何反馈吗? 我们很乐意听取您的意见!