mybatis-generator-gui根据需求改动示例
作者:晓晓先生
这篇文章主要为大家介绍了mybatis-generator-gui根据需求改动示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
JavaType解析类
改的都是自己觉得需要改的部分
在生成的实体类中,数据库tinyint类型默认会生成Byte,使用时略有不便。于是将其改成Integer。
- 自定义一个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; } }
- 在加载配置的过程中进行加载即可(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); }
去掉不必要的默认勾选
- 找到MainUI.fxml;
找到对应的checkbox,把selected修改为false即可。
生成lombok常用注解
- 自定义lombok插件
package com.zzg.mybatis.generator.plugins; public class LombokPlugin extends PluginAdapter { public LombokPlugin() { } @Override public boolean validate(List<String> 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); } }
在加载配置的过程中进行加载即可(加到MybatisGeneratorBridge:182下面)
生成的DAO层类改为默认Mapper结尾
找到MainUIController:212行,把“DAO”改为“Mapper”即可。
以上就是mybatis-generator-gui根据需求改动示例的详细内容,更多关于mybatis-generator-gui改动的资料请关注脚本之家其它相关文章!