[英]How to configure the base class for 'Example' generated by mybatis generator plug-in
如何为mybatis生成器插件生成的“Example”配置基类,或者生成器插件是否可以为“Example”配置基类?
It would be possible with a custom plugin . 使用自定义插件是可能的。
If extending the base class is all you need, it is easy. 如果只需要扩展基类,就很容易了。
package mygroup.myplugin;
import java.util.List;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.TopLevelClass;
public class ExampleSuperclassPlugin extends PluginAdapter {
@Override
public boolean validate(List<String> warnings) {
return true;
}
@Override
public boolean modelExampleClassGenerated(
TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
// Add import
topLevelClass.addImportedType(new FullyQualifiedJavaType("your.pkg.ExampleBase"));
// Add 'extends ExampleBase'
topLevelClass.setSuperClass("ExampleBase");
return true;
}
}
In generatorConfig.xml
, add <plugin />
entry. 在
generatorConfig.xml
,添加<plugin />
条目。
<generatorConfiguration>
...
<context ...>
<plugin type="mygroup.myplugin.ExampleSuperclassPlugin" />
...
Make sure that the custom plugin JAR is included in the classpath when running Generator. 运行Generator时,请确保自定义插件JAR包含在类路径中。 If you use Generator Maven Plugin, for example, add it as a dependency to the plugin in
pom.xml
. 例如,如果您使用Generator Maven插件,请将其作为依赖项添加到
pom.xml
的插件中。
<build>
...
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>myplugin</artifactId>
<version>0.0.1</version>
</dependency>
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.