MatcherRule
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
大多数匹配器使用对 MatcherRule 的引用,它由两个元素组成
- 用于替换匹配名称的正则表达式替换表达式。
- 转换指令,允许指定如何转换结果名称。
转换指令
支持以下转换指令
-
AS_IS:保持数据库名称不变,例如MY_name=>MY_name -
LOWER:将数据库名称转换为小写,例如MY_name=>my_name -
LOWER_FIRST_LETTER:将首字母转换为小写,例如MY_name=>mY_name -
UPPER:将数据库名称转换为大写,例如MY_name=>MY_NAME -
UPPER_FIRST_LETTER:将首字母转换为大写,例如my_NAME=>My_NAME -
CAMEL:将数据库名称转换为驼峰式命名,例如MY_name=>myName -
PASCAL:将数据库名称转换为帕斯卡式命名,例如MY_name=>MyName
示例:向名称添加前缀/后缀
XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
<generator>
<strategy>
<matchers>
<schemas>
<schema>
<!-- Without an input expression, this rule applies to all schemas -->
<schemaClass>
<!-- Optional transform directive -->
<transform>CAMEL</transform>
<!-- The mandatory expression element lets you specify a replacement expression to be used when
replacing the matcher's regular expression. You can use indexed variables $0, $1, $2. -->
<expression>PREFIX_$0_SUFFIX</expression>
</schemaClass>
</schema>
</schemas>
</matchers>
</strategy>
</generator>
</configuration>
有关更多详细信息,请参阅 configuration XSD、独立代码生成 以及 maven 代码生成。
new org.jooq.meta.jaxb.Configuration()
.withGenerator(new Generator()
.withStrategy(new Strategy()
.withMatchers(new Matchers()
.withSchemas(
new MatchersSchemaType()
// Without an input expression, this rule applies to all schemas
.withSchemaClass(new MatcherRule()
// Optional transform directive
.withTransform(MatcherTransformType.CAMEL)
// The mandatory expression element lets you specify a replacement expression to be used when
// replacing the matcher's regular expression. You can use indexed variables $0, $1, $2.
.withExpression("PREFIX_$0_SUFFIX")
)
)
)
)
)
有关更多详细信息,请参阅 configuration XSD 和 程序化代码生成。
import org.jooq.meta.jaxb.*
configuration {
generator {
strategy {
matchers {
schemas {
schema {
// Without an input expression, this rule applies to all schemas
schemaClass {
// Optional transform directive
transform = MatcherTransformType.CAMEL
// The mandatory expression element lets you specify a replacement expression to be used when
// replacing the matcher's regular expression. You can use indexed variables $0, $1, $2.
expression = "PREFIX_$0_SUFFIX"
}
}
}
}
}
}
}
有关更多详细信息,请参阅 configuration XSD 和 gradle 代码生成。
configuration {
generator {
strategy {
matchers {
schemas {
schema {
// Without an input expression, this rule applies to all schemas
schemaClass {
// Optional transform directive
transform = "CAMEL"
// The mandatory expression element lets you specify a replacement expression to be used when
// replacing the matcher's regular expression. You can use indexed variables $0, $1, $2.
expression = "PREFIX_$0_SUFFIX"
}
}
}
}
}
}
}
有关更多详细信息,请参阅 configuration 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.
一如既往,当使用正则表达式时,它们是具有默认标志的正则表达式。
示例:从名称中删除前缀/后缀
XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
<generator>
<strategy>
<matchers>
<tables>
<table>
<!-- Provide an optional input expression to apply this rule only to certain tables.
We can match groups with the regex (group expression) -->
<expression>^T_(.*)$</expression>
<tableClass>
<!-- Optional transform directive -->
<transform>CAMEL</transform>
<!-- This ignores the prefix and replaces the name by the first matched group. -->
<expression>$1</expression>
</tableClass>
</table>
</tables>
</matchers>
</strategy>
</generator>
</configuration>
有关更多详细信息,请参阅 configuration XSD、独立代码生成 以及 maven 代码生成。
new org.jooq.meta.jaxb.Configuration()
.withGenerator(new Generator()
.withStrategy(new Strategy()
.withMatchers(new Matchers()
.withTables(
new MatchersTableType()
// Provide an optional input expression to apply this rule only to certain tables.
// We can match groups with the regex (group expression)
.withExpression("^T_(.*)$")
.withTableClass(new MatcherRule()
// Optional transform directive
.withTransform(MatcherTransformType.CAMEL)
// This ignores the prefix and replaces the name by the first matched group.
.withExpression("$1")
)
)
)
)
)
有关更多详细信息,请参阅 configuration XSD 和 程序化代码生成。
import org.jooq.meta.jaxb.*
configuration {
generator {
strategy {
matchers {
tables {
table {
// Provide an optional input expression to apply this rule only to certain tables.
// We can match groups with the regex (group expression)
expression = "^T_(.*)$"
tableClass {
// Optional transform directive
transform = MatcherTransformType.CAMEL
// This ignores the prefix and replaces the name by the first matched group.
expression = "$1"
}
}
}
}
}
}
}
有关更多详细信息,请参阅 configuration XSD 和 gradle 代码生成。
configuration {
generator {
strategy {
matchers {
tables {
table {
// Provide an optional input expression to apply this rule only to certain tables.
// We can match groups with the regex (group expression)
expression = "^T_(.*)$"
tableClass {
// Optional transform directive
transform = "CAMEL"
// This ignores the prefix and replaces the name by the first matched group.
expression = "$1"
}
}
}
}
}
}
}
有关更多详细信息,请参阅 configuration 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.
一如既往,当使用正则表达式时,它们是具有默认标志的正则表达式。
换句话说,MatcherRule 描述了如何根据对象的输入名称声明和引用特定的对象类型名称(例如,表示生成的 org.jooq.Schema 的类名)。
反馈
您对此页面有任何反馈吗? 我们很乐意听到您的反馈!