更新时间:2023-09-30 16:04:04
这可以使用
使用生成器策略,您将实现以下代码:
With a generator strategy, you'll implement the following code:
public class MyStrategy extends DefaultGeneratorStrategy {
@Override
public List<String> getJavaClassImplements(Definition definition, Mode mode) {
if (mode == Mode.RECORD && definition.getQualifiedName().matches("some regex")) {
return Arrays.asList(MyCustomInterface.class.getName());
}
}
}
然后可以将上述内容钩入您的代码生成器配置中,如下所示:
The above can then be hooked into your code generator configuration as such:
<generator>
<strategy>
<name>com.example.MyStrategy</name>
</strategy>
</generator>
使用匹配器策略,您基本上可以这样写:
With a matcher strategy, you'll essentially write:
<generator>
<strategy>
<matchers>
<tables>
<table>
<expression>A_REGEX_MATCHING_ALL_RELEVANT_TABLES</expression>
<recordImplements>com.example.MyCustomInterface</recordImplements>
</table>
</tables>
</matchers>
</strategy>
</generator>
如您所见,对于像您这样的简单用例,匹配器策略比生成器策略更易于配置.
As you can see, matcher strategies are easier to configure than generator strategy, for simple use-cases like yours.