實體Bean的文件名變動。java
package plugin; import java.util.List; import org.mybatis.generator.api.IntrospectedTable; import org.mybatis.generator.api.PluginAdapter; public class BeanClassNamePlugin extends PluginAdapter { @Override public boolean validate(List<String> warnings) { return true; } @Override public void initialized(IntrospectedTable table) { super.initialized(table); String name = table.getBaseRecordType(); table.setBaseRecordType(name + "Dto"); } }
2.特定接口實現。shell
package plugin; import java.util.List; import org.mybatis.generator.api.FullyQualifiedTable; import org.mybatis.generator.api.PluginAdapter; import org.mybatis.generator.api.IntrospectedTable; import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; public class BeanImplementationPlugin extends PluginAdapter { private FullyQualifiedJavaType bean; public BeanImplementationPlugin() { bean = new FullyQualifiedJavaType( "net.kronosjp.jyukutyo.MyInterface"); } public boolean validate(List<String> warnings) { return true; } public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { implementBean( topLevelClass, introspectedTable.getFullyQualifiedTable()); return true; } public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { implementBean( topLevelClass, introspectedTable.getFullyQualifiedTable()); return true; } public boolean modelRecordWithBLOBsClassGenerated( TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { implementBean( topLevelClass, introspectedTable.getFullyQualifiedTable()); return true; } protected void implementBean(TopLevelClass topLevelClass, FullyQualifiedTable table) { topLevelClass.addImportedType(bean); topLevelClass.addSuperInterface(bean); } }
3.Mapper類名變動。api
package plugin; import java.util.List; import org.mybatis.generator.api.IntrospectedTable; import org.mybatis.generator.api.PluginAdapter; public class MapperClassNamePlugin extends PluginAdapter { @Override public boolean validate(List<String> warnings) { return true; } @Override public void initialized(IntrospectedTable table) { super.initialized(table); String name = table.getMyBatis3JavaMapperType(); table.setMyBatis3JavaMapperType(name.replaceAll("Mapper$", "Dao")); } }
使用:mybatis
<plugin type="plugin.MapperClassNamePlugin" /> <plugin type="plugin.DtoExtendedPlugin" />