mybatis-generator-gui魔改,改完之后更方便了呢

改的都是自己觉得需要改的部分,如有不同见解欢迎讨论。

在生成的实体类中,数据库tinyint类型默认会生成Byte,使用时略有不便。于是将其改成Integer。

  1. 自定义一个JavaType解析的类
package com.zzg.mybatis.generator.plugins;
public class MyJavaTypeResolverImpl extends JavaTypeResolverDefaultImpl {
    @Override
    protected FullyQualifiedJavaType overrideDefaultType(IntrospectedColumn column, FullyQualifiedJavaType defaultType) {
        FullyQualifiedJavaType answer = defaultType;
        switch (column.getJdbcType()) {
            case Types.TINYINT:
                answer = new FullyQualifiedJavaType(Integer.class.getName());
                break;
            default:
                break;
        }
        return answer;
    }
}
  1. 在加载配置的过程中进行加载即可(MybatisGeneratorBridge:210)
//for JSR310
        if (generatorConfig.isJsr310Support()) {
            JavaTypeResolverConfiguration javaTypeResolverConfiguration = new JavaTypeResolverConfiguration();
           javaTypeResolverConfiguration.setConfigurationType("com.zzg.mybatis.generator.plugins.JavaTypeResolverJsr310Impl");
            context.setJavaTypeResolverConfiguration(javaTypeResolverConfiguration);
        } else {
            // 《TINYINT的JavaType改为Integer》
            JavaTypeResolverConfiguration myJavaTypeResolverConfiguration = new JavaTypeResolverConfiguration();
           myJavaTypeResolverConfiguration.setConfigurationType("com.zzg.mybatis.generator.plugins.MyJavaTypeResolverImpl");
            context.setJavaTypeResolverConfiguration(myJavaTypeResolverConfiguration);
        }

去掉不必要的默认勾选

  1. 找到MainUI.fxml;
  2. 找到对应的checkbox,把selected修改为false即可。

    image.png

生成lombok常用注解

  1. 自定义lombok插件
package com.zzg.mybatis.generator.plugins;

public class LombokPlugin extends PluginAdapter {
    public LombokPlugin() {
    }

    @Override
    public boolean validate(List list) {
        return true;
    }

    @Override
    public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        topLevelClass.addImportedType("lombok.Data");
        topLevelClass.addAnnotation("@Data");
        topLevelClass.addImportedType("lombok.ToString");
        topLevelClass.addAnnotation("@ToString");
        topLevelClass.addImportedType("lombok.Builder");
        topLevelClass.addAnnotation("@Builder");
        topLevelClass.addImportedType("lombok.NoArgsConstructor");
        topLevelClass.addAnnotation("@NoArgsConstructor");
        topLevelClass.addImportedType("lombok.AllArgsConstructor");
        topLevelClass.addAnnotation("@AllArgsConstructor");
        topLevelClass.addJavaDocLine("/**");
        topLevelClass.addJavaDocLine("* @author 我");
        topLevelClass.addJavaDocLine("* @date " + this.date2Str(new Date()));
        topLevelClass.addJavaDocLine("*/");
        return true;
    }

    @Override
    public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        interfaze.addJavaDocLine("/**");
        interfaze.addJavaDocLine("* @author 我");
        interfaze.addJavaDocLine("* @date " + this.date2Str(new Date()));
        interfaze.addJavaDocLine("*/");
        return true;
    }

    @Override
    public boolean modelSetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
        return false;
    }

    @Override
    public boolean modelGetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
        return false;
    }

    private String date2Str(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        return sdf.format(date);
    }
}


  1. 在加载配置的过程中进行加载即可(加到MybatisGeneratorBridge:182下面)

    image.png

生成的DAO层类改为默认Mapper结尾

找到MainUIController:212行,把“DAO”改为“Mapper”即可。

版权声明:
作者:lichengxin
链接:https://www.techfm.club/p/42806.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>