当前位置: 代码迷 >> 综合 >> mybatis-generator-gui魔改,改完之后更方便了呢
  详细解决方案

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

热度:32   发布时间:2023-10-24 08:11:07.0

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

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

  1. 自定义一个JavaType解析的类
package com.zzg.mybatis.generator.plugins;
public class MyJavaTypeResolverImpl extends JavaTypeResolverDefaultImpl {
    @Overrideprotected 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 JSR310if (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即可。
    mybatis-generator-gui魔改,改完之后更方便了呢

生成lombok常用注解

  1. 自定义lombok插件
package com.zzg.mybatis.generator.plugins;public class LombokPlugin extends PluginAdapter {
    public LombokPlugin() {
    }@Overridepublic boolean validate(List<String> list) {
    return true;}@Overridepublic 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;}@Overridepublic boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    interfaze.addJavaDocLine("/**");interfaze.addJavaDocLine("* @author 我");interfaze.addJavaDocLine("* @date " + this.date2Str(new Date()));interfaze.addJavaDocLine("*/");return true;}@Overridepublic boolean modelSetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
    return false;}@Overridepublic 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下面)
    mybatis-generator-gui魔改,改完之后更方便了呢

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

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


喜欢本文的朋友不要忘记点一个免费的赞哦,你的赞将是我最大的动力。

  相关解决方案