适用于版本:Dev (3.21) | 最新 (3.20) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11

生成器

适用于 ✅ 开源版   ✅ 专业版   ✅ 企业版

这个必需的顶级配置元素包裹了所有与代码生成相关的剩余配置元素,包括可覆盖的代码生成器类。

XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
  <generator>

    <!-- Optional: The fully qualified class name of the code generator. Available generators:

         - org.jooq.codegen.JavaGenerator
         - org.jooq.codegen.KotlinGenerator
         - org.jooq.codegen.ScalaGenerator

         Defaults to org.jooq.codegen.JavaGenerator -->
    <name>...</name>

    <!-- Optional: The implementation of the code generator, written in Java -->
    <java>...</java>

    <!-- Optional: The programmatic or configurative generator strategy. -->
    <strategy/>

    <!-- Optional: The jooq-meta configuration, configuring the information schema source. -->
    <database/>

    <!-- Optional: The jooq-codegen configuration, configuring the generated output content. -->
    <generate/>

    <!-- Optional: The generation output target -->
    <target/>
  </generator>
</configuration>

有关更多详细信息,请参阅配置 XSD独立代码生成,以及Maven 代码生成

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()

    // Optional: The fully qualified class name of the code generator. Available generators:
    // 
    // - org.jooq.codegen.JavaGenerator
    // - org.jooq.codegen.KotlinGenerator
    // - org.jooq.codegen.ScalaGenerator
    // 
    // Defaults to org.jooq.codegen.JavaGenerator
    .withName(...)

    // Optional: The implementation of the code generator, written in Java
    .withJava(...)

    // Optional: The programmatic or configurative generator strategy.
    .withStrategy()

    // Optional: The jooq-meta configuration, configuring the information schema source.
    .withDatabase()

    // Optional: The jooq-codegen configuration, configuring the generated output content.
    .withGenerate()

    // Optional: The generation output target
    .withTarget()
  )

有关更多详细信息,请参阅配置 XSD程序化代码生成

import org.jooq.meta.jaxb.*


configuration {
  generator {

    // Optional: The fully qualified class name of the code generator. Available generators:
    // 
    // - org.jooq.codegen.JavaGenerator
    // - org.jooq.codegen.KotlinGenerator
    // - org.jooq.codegen.ScalaGenerator
    // 
    // Defaults to org.jooq.codegen.JavaGenerator
    name = ...

    // Optional: The implementation of the code generator, written in Java
    java = ...

    // Optional: The programmatic or configurative generator strategy.
    strategy {}

    // Optional: The jooq-meta configuration, configuring the information schema source.
    database {}

    // Optional: The jooq-codegen configuration, configuring the generated output content.
    generate {}

    // Optional: The generation output target
    target {}
  }
}

有关更多详细信息,请参阅配置 XSDGradle 代码生成

configuration {
  generator {

    // Optional: The fully qualified class name of the code generator. Available generators:
    // 
    // - org.jooq.codegen.JavaGenerator
    // - org.jooq.codegen.KotlinGenerator
    // - org.jooq.codegen.ScalaGenerator
    // 
    // Defaults to org.jooq.codegen.JavaGenerator
    name = ...

    // Optional: The implementation of the code generator, written in Java
    java = ...

    // Optional: The programmatic or configurative generator strategy.
    strategy {}

    // Optional: The jooq-meta configuration, configuring the information schema source.
    database {}

    // Optional: The jooq-codegen configuration, configuring the generated output content.
    generate {}

    // Optional: The generation output target
    target {}
  }
}

有关更多详细信息,请参阅配置 XSDGradle 代码生成

// 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/> 元素允许指定用户定义的生成器实现。这在生成自定义代码段时最为有用,可以使用代码生成器的内部 API 以编程方式添加自定义代码段。 有关更多详细信息,请参阅手册的相关部分。

这可以通过加载先前编译的类来完成,也可以通过提供内联实现来完成(有关更多详细信息,请参阅内存编译)。

XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
  <generator>
    <name>com.example.MyGenerator</name>
    <java>package com.example;

import org.jooq.codegen.JavaGenerator;

public class MyGenerator extends JavaGenerator {
    ...
}</java>
  </generator>
</configuration>

有关更多详细信息,请参阅配置 XSD独立代码生成,以及Maven 代码生成

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()
    .withName("com.example.MyGenerator")
    .withJava("""package com.example;

import org.jooq.codegen.JavaGenerator;

public class MyGenerator extends JavaGenerator {
    ...
}""")
  )

有关更多详细信息,请参阅配置 XSD程序化代码生成

import org.jooq.meta.jaxb.*


configuration {
  generator {
    name = "com.example.MyGenerator"
    java = """package com.example;

import org.jooq.codegen.JavaGenerator;

public class MyGenerator extends JavaGenerator {
    ...
}"""
  }
}

有关更多详细信息,请参阅配置 XSDGradle 代码生成

configuration {
  generator {
    name = "com.example.MyGenerator"
    java = """package com.example;

import org.jooq.codegen.JavaGenerator;

public class MyGenerator extends JavaGenerator {
    ...
}"""
  }
}

有关更多详细信息,请参阅配置 XSDGradle 代码生成

// 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.
确保您的自定义生成器的依赖项(或生成器本身,如果按名称引用)作为代码生成依赖项可供代码生成器使用

指定策略

jOOQ 默认应用标准的 Java 命名方案:类使用 PascalCase,成员、方法、变量、参数使用 camelCase,常量和其他字面量使用 UPPER_CASE_WITH_UNDERSCORES。这可能不是您的数据库所期望的默认设置,例如,当您强烈依赖区分大小写的命名,并且希望能够在 Java 代码和数据库代码(脚本、视图、存储过程)中统一搜索名称时。为此,您可以覆盖 <strategy/> 元素,使用您自己的实现,可以通过

有关更多详细信息,请参阅上面的相关部分。

反馈

您对此页面有任何反馈吗? 我们很乐意听取您的意见!

The jOOQ Logo