博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
定制MyBatis Generator输出内容
阅读量:7081 次
发布时间:2019-06-28

本文共 2662 字,大约阅读时间需要 8 分钟。

hot3.png

  1. 实体Bean的文件名变更。

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
 warnings) {        return true;    }    @Override    public void initialized(IntrospectedTable table) {        super.initialized(table);        String name = table.getBaseRecordType();        table.setBaseRecordType(name + "Dto");    }}

2.特定接口实现。

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
 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类名变更。

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
 warnings) {  return true; } @Override public void initialized(IntrospectedTable table) {  super.initialized(table);    String name = table.getMyBatis3JavaMapperType();  table.setMyBatis3JavaMapperType(name.replaceAll("Mapper$", "Dao")); }}

使用:

  
  

转载于:https://my.oschina.net/u/133911/blog/537595

你可能感兴趣的文章
iOS少用的框架
查看>>
ups锂电池的优势
查看>>
关于程序员和***区别在哪里?
查看>>
tomcat启动报错Invalid character found in method name. HTTP method names must be tokens
查看>>
appium+python3.6
查看>>
RAID cache的作用及更换RAID 电池注意事项
查看>>
如何挖掘和优化长尾关键词?
查看>>
windows下安装解压版mysql
查看>>
Linux启用ssh服务
查看>>
Centos7 Snapper快照备份
查看>>
cdn
查看>>
每一天的成长由此开始
查看>>
swift开发中如何将时间显示为几分钟前、几小时前、几天前、几个月前
查看>>
某店订单系统水平分库的实践之路以及关键步骤
查看>>
Oracle GoldenGate 快速安装配置实用指南
查看>>
我的友情链接
查看>>
iOS 图片合并 及截图
查看>>
easyui datagrid load 方法键不能为变量的解决
查看>>
分治的一次简单实践
查看>>
博为峰Java面试题-JavaSE I/O之File写入读出
查看>>