Explorar el Código

优化策略配置项.

nieqiurong hace 4 años
padre
commit
987796063d
Se han modificado 14 ficheros con 1180 adiciones y 266 borrados
  1. 2 2
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/INameConvert.java
  2. 543 228
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java
  3. 41 0
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/BaseBuilder.java
  4. 3 3
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilder.java
  5. 80 0
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/ControllerBuilder.java
  6. 329 0
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/EntityBuilder.java
  7. 46 0
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/MapperBuilder.java
  8. 70 0
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/ServiceBuilder.java
  9. 3 3
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/po/TableField.java
  10. 7 7
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/po/TableInfo.java
  11. 20 20
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/engine/AbstractTemplateEngine.java
  12. 1 1
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/po/TableInfoTest.java
  13. 1 1
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/MysqlGenerator.java
  14. 34 1
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/StrategyConfigTest.java

+ 2 - 2
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/INameConvert.java

@@ -62,12 +62,12 @@ public interface INameConvert {
 
         @Override
         public String entityNameConvert(TableInfo tableInfo) {
-            return NamingStrategy.capitalFirst(processName(tableInfo.getName(), strategyConfig.getNaming(), strategyConfig.getTablePrefix()));
+            return NamingStrategy.capitalFirst(processName(tableInfo.getName(), strategyConfig.entity().getNaming(), strategyConfig.getTablePrefix()));
         }
 
         @Override
         public String propertyNameConvert(TableField field) {
-            return processName(field.getName(), strategyConfig.getNaming(), strategyConfig.getTablePrefix());
+            return processName(field.getName(), strategyConfig.entity().getNaming(), strategyConfig.getTablePrefix());
         }
 
         private String processName(String name, NamingStrategy strategy, Set<String> prefix) {

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 543 - 228
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java


+ 41 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/BaseBuilder.java

@@ -0,0 +1,41 @@
+package com.baomidou.mybatisplus.generator.config.builder;
+
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import lombok.AccessLevel;
+import lombok.Getter;
+
+/**
+ * 基础属性配置
+ *
+ * @author nieqiurong 2020/10/11.
+ * @since 3.4.1
+ */
+public class BaseBuilder {
+
+    @Getter(AccessLevel.NONE)
+    private final StrategyConfig strategyConfig;
+
+    public BaseBuilder(StrategyConfig strategyConfig) {
+        this.strategyConfig = strategyConfig;
+    }
+
+    public EntityBuilder entity() {
+        return strategyConfig.entity();
+    }
+
+    public ControllerBuilder controller() {
+        return strategyConfig.controller();
+    }
+
+    public MapperBuilder mapper() {
+        return strategyConfig.mapper();
+    }
+
+    public ServiceBuilder service() {
+        return strategyConfig.service();
+    }
+
+    public StrategyConfig build() {
+        return this.strategyConfig;
+    }
+}

+ 3 - 3
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilder.java

@@ -223,15 +223,15 @@ public class ConfigBuilder {
                 }
                 field.setName(columnName).setColumnName(newColumnName)
                     .setType(result.getStringResult(dbQuery.fieldType()))
-                    .setPropertyName(strategyConfig.getNameConvert().propertyNameConvert(field), this.strategyConfig, dataSourceConfig.getTypeConvert().processTypeConvert(globalConfig, field))
+                    .setPropertyName(strategyConfig.entity().getNameConvert().propertyNameConvert(field), this.strategyConfig, dataSourceConfig.getTypeConvert().processTypeConvert(globalConfig, field))
                     .setComment(result.getFiledComment())
                     .setCustomMap(dbQuery.getCustomFields(result.getResultSet()));
                 // 填充逻辑判断
-                strategyConfig.getTableFillList().stream()
+                strategyConfig.entity().getTableFillList().stream()
                     //忽略大写字段问题
                     .filter(tf -> tf.getFieldName().equalsIgnoreCase(field.getName()))
                     .findFirst().ifPresent(tf -> field.setFill(tf.getFieldFill().name()));
-                if (strategyConfig.matchSuperEntityColumns(field.getName())) {
+                if (strategyConfig.entity().matchSuperEntityColumns(field.getName())) {
                     // 跳过公共字段
                     commonFieldList.add(field);
                 } else {

+ 80 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/ControllerBuilder.java

@@ -0,0 +1,80 @@
+package com.baomidou.mybatisplus.generator.config.builder;
+
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import lombok.Getter;
+
+/**
+ * 控制器属性配置
+ *
+ * @author nieqiurong 2020/10/11.
+ * @since 3.4.1
+ */
+@Getter
+public class ControllerBuilder extends BaseBuilder {
+
+    /**
+     * 生成 <code>@RestController</code> 控制器
+     * <pre>
+     *      <code>@Controller</code> -> <code>@RestController</code>
+     * </pre>
+     */
+    private boolean restStyle = false;
+    /**
+     * 驼峰转连字符
+     * <pre>
+     *      <code>@RequestMapping("/managerUserActionHistory")</code> -> <code>@RequestMapping("/manager-user-action-history")</code>
+     * </pre>
+     */
+    private boolean hyphenStyle = false;
+
+    /**
+     * 自定义继承的Controller类全称,带包名
+     */
+    private String superClass;
+
+    public ControllerBuilder(StrategyConfig strategyConfig) {
+        super(strategyConfig);
+    }
+
+    /**
+     * 父类控制器
+     *
+     * @param clazz 父类控制器
+     * @return this
+     */
+    public ControllerBuilder superClass(Class<?> clazz) {
+        return superClass(clazz.getName());
+    }
+
+    /**
+     * 父类控制器
+     *
+     * @param superClass 父类控制器类名
+     * @return this
+     */
+    public ControllerBuilder superClass(String superClass) {
+        this.superClass = superClass;
+        return this;
+    }
+
+    /**
+     * 是否驼峰转连字符
+     *
+     * @return this
+     */
+    public ControllerBuilder hyphenStyle(boolean hyphenStyle) {
+        this.hyphenStyle = hyphenStyle;
+        return this;
+    }
+
+    /**
+     * 生成@RestController控制器
+     *
+     * @param restStyle 是否生成@RestController控制器
+     * @return this
+     */
+    public ControllerBuilder restStyle(boolean restStyle) {
+        this.restStyle = restStyle;
+        return this;
+    }
+}

+ 329 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/EntityBuilder.java

@@ -0,0 +1,329 @@
+package com.baomidou.mybatisplus.generator.config.builder;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
+import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.generator.config.INameConvert;
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import com.baomidou.mybatisplus.generator.config.po.TableFill;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * 实体属性配置
+ *
+ * @author nieqiurong 2020/10/11.
+ * @since 3.4.1
+ */
+@Getter
+public class EntityBuilder extends BaseBuilder {
+
+    public EntityBuilder(StrategyConfig strategyConfig) {
+        super(strategyConfig);
+        this.nameConvert = new INameConvert.DefaultNameConvert(strategyConfig);
+    }
+
+    /**
+     * 名称转换
+     */
+    private INameConvert nameConvert;
+
+    /**
+     * 自定义继承的Entity类全称,带包名
+     */
+    @Setter(AccessLevel.NONE)
+    private String superClass;
+
+    /**
+     * 自定义基础的Entity类,公共字段
+     */
+    @Setter(AccessLevel.NONE)
+    private final Set<String> superEntityColumns = new HashSet<>();
+
+    /**
+     * 实体是否生成 serialVersionUID
+     */
+    private boolean serialVersionUID;
+
+    /**
+     * 【实体】是否生成字段常量(默认 false)<br>
+     * -----------------------------------<br>
+     * public static final String ID = "test_id";
+     */
+    private boolean columnConstant;
+
+    /**
+     * 【实体】是否为链式模型(默认 false)<br>
+     * -----------------------------------<br>
+     * public User setName(String name) { this.name = name; return this; }
+     *
+     * @since 3.3.2
+     */
+    private boolean chain;
+
+    /**
+     * 【实体】是否为lombok模型(默认 false)<br>
+     * <a href="https://projectlombok.org/">document</a>
+     */
+    private boolean lombok;
+
+    /**
+     * Boolean类型字段是否移除is前缀(默认 false)<br>
+     * 比如 : 数据库字段名称 : 'is_xxx',类型为 : tinyint. 在映射实体的时候则会去掉is,在实体类中映射最终结果为 xxx
+     */
+    private boolean booleanColumnRemoveIsPrefix;
+
+    /**
+     * 是否生成实体时,生成字段注解
+     */
+    private boolean tableFieldAnnotationEnable;
+
+    /**
+     * 乐观锁属性名称
+     */
+    private String versionFieldName;
+
+    /**
+     * 逻辑删除属性名称
+     */
+    private String logicDeleteFieldName;
+
+    /**
+     * 表填充字段
+     */
+    private final List<TableFill> tableFillList = new ArrayList<>();
+
+    /**
+     * 数据库表映射到实体的命名策略
+     */
+    private NamingStrategy naming = NamingStrategy.no_change;
+
+    /**
+     * 数据库表字段映射到实体的命名策略
+     * <p>未指定按照 naming 执行</p>
+     */
+    private NamingStrategy columnNaming = null;
+
+    /**
+     * 名称转换实现
+     *
+     * @param nameConvert 名称转换实现
+     * @return this
+     */
+    public EntityBuilder nameConvert(INameConvert nameConvert) {
+        this.nameConvert = nameConvert;
+        return this;
+    }
+
+    public EntityBuilder superClass(Class<?> clazz) {
+        this.superClass = clazz.getName();
+        return this;
+    }
+
+    public EntityBuilder superClass(String superEntityClass) {
+        this.superClass = superEntityClass;
+        return this;
+    }
+
+    /**
+     * 实体是否生成serialVersionUID
+     *
+     * @param serialVersionUID 是否生成
+     * @return this
+     */
+    public EntityBuilder serialVersionUID(boolean serialVersionUID) {
+        this.serialVersionUID = serialVersionUID;
+        return this;
+    }
+
+    /**
+     * 是否生成字段常量
+     *
+     * @param columnConstant 是否生成字段常量
+     * @return this
+     */
+    public EntityBuilder columnConstant(boolean columnConstant) {
+        this.columnConstant = columnConstant;
+        return this;
+    }
+
+    /**
+     * 实体是否为链式模型
+     *
+     * @param chain 是否为链式模型
+     * @return this
+     */
+    public EntityBuilder chainModel(boolean chain) {
+        this.chain = chain;
+        return this;
+    }
+
+    /**
+     * 是否为lombok模型
+     *
+     * @param lombok 是否为lombok模型
+     * @return this
+     */
+    public EntityBuilder lombok(boolean lombok) {
+        this.lombok = lombok;
+        return this;
+    }
+
+    /**
+     * Boolean类型字段是否移除is前缀
+     *
+     * @param booleanColumnRemoveIsPrefix 是否移除
+     * @return this
+     */
+    public EntityBuilder booleanColumnRemoveIsPrefix(boolean booleanColumnRemoveIsPrefix) {
+        this.booleanColumnRemoveIsPrefix = booleanColumnRemoveIsPrefix;
+        return this;
+    }
+
+    /**
+     * 生成实体时,是否生成字段注解
+     *
+     * @param tableFieldAnnotationEnable 是否生成
+     * @return this
+     */
+    public EntityBuilder tableFieldAnnotationEnable(boolean tableFieldAnnotationEnable) {
+        this.tableFieldAnnotationEnable = tableFieldAnnotationEnable;
+        return this;
+    }
+
+    /**
+     * 乐观锁属性名称
+     *
+     * @param versionFieldName 乐观锁属性名称
+     * @return this
+     */
+    public EntityBuilder versionFieldName(String versionFieldName) {
+        this.versionFieldName = versionFieldName;
+        return this;
+    }
+
+    /**
+     * 逻辑删除属性名称
+     *
+     * @param logicDeleteFieldName 逻辑删除属性名称
+     * @return this
+     */
+    public EntityBuilder logicDeleteFieldName(String logicDeleteFieldName) {
+        this.logicDeleteFieldName = logicDeleteFieldName;
+        return this;
+    }
+
+    public EntityBuilder naming(NamingStrategy namingStrategy) {
+        this.naming = namingStrategy;
+        return this;
+    }
+
+    public EntityBuilder columnNaming(NamingStrategy namingStrategy) {
+        this.columnNaming = namingStrategy;
+        return this;
+    }
+
+    /**
+     * 添加父类公共字段
+     *
+     * @param superEntityColumns 父类字段(数据库字段列名)
+     * @return this
+     * @since 3.4.1
+     */
+    public EntityBuilder addSuperEntityColumns(String... superEntityColumns) {
+        this.superEntityColumns.addAll(Arrays.asList(superEntityColumns));
+        return this;
+    }
+
+    /**
+     * 添加表字段填充
+     *
+     * @param tableFill 填充字段
+     * @return this
+     * @since 3.4.1
+     */
+    public EntityBuilder addTableFills(TableFill... tableFill) {
+        this.tableFillList.addAll(Arrays.asList(tableFill));
+        return this;
+    }
+
+    /**
+     * 添加表字段填充
+     *
+     * @param tableFillList 填充字段集合
+     * @return this
+     * @since 3.4.1
+     */
+    public EntityBuilder addTableFills(List<TableFill> tableFillList) {
+        this.tableFillList.addAll(tableFillList);
+        return this;
+    }
+
+    /**
+     * <p>
+     * 父类 Class 反射属性转换为公共字段
+     * </p>
+     *
+     * @param clazz 实体父类 Class
+     */
+    public void convertSuperEntityColumns(Class<?> clazz) {
+        List<Field> fields = TableInfoHelper.getAllFields(clazz);
+        this.superEntityColumns.addAll(fields.stream().map(field -> {
+            TableId tableId = field.getAnnotation(TableId.class);
+            if (tableId != null && StringUtils.isNotBlank(tableId.value())) {
+                return tableId.value();
+            }
+            TableField tableField = field.getAnnotation(TableField.class);
+            if (tableField != null && StringUtils.isNotBlank(tableField.value())) {
+                return tableField.value();
+            }
+            if (null == columnNaming || columnNaming == NamingStrategy.no_change) {
+                return field.getName();
+            }
+            return StringUtils.camelToUnderline(field.getName());
+        }).collect(Collectors.toSet()));
+    }
+
+    public Set<String> getSuperEntityColumns() {
+        if (StringUtils.isNotBlank(this.superClass)) {
+            try {
+                Class<?> superEntity = ClassUtils.toClassConfident(this.superClass);
+                convertSuperEntityColumns(superEntity);
+            } catch (Exception e) {
+                //当父类实体存在类加载器的时候,识别父类实体字段,不存在的情况就只有通过指定superEntityColumns属性了。
+            }
+        }
+        return this.superEntityColumns;
+    }
+
+    public NamingStrategy getColumnNaming() {
+        // 未指定以 naming 策略为准
+        return Optional.ofNullable(columnNaming).orElse(naming);
+    }
+
+    /**
+     * 匹配父类字段(忽略大小写)
+     *
+     * @param fieldName 字段名
+     * @return 是否匹配
+     * @since 3.4.1
+     */
+    public boolean matchSuperEntityColumns(String fieldName) {
+        // 公共字段判断忽略大小写【 部分数据库大小写不敏感 】
+        return superEntityColumns.stream().anyMatch(e -> e.equalsIgnoreCase(fieldName));
+    }
+
+}

+ 46 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/MapperBuilder.java

@@ -0,0 +1,46 @@
+package com.baomidou.mybatisplus.generator.config.builder;
+
+import com.baomidou.mybatisplus.generator.config.ConstVal;
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import lombok.Getter;
+
+/**
+ * 控制器属性配置
+ *
+ * @author nieqiurong 2020/10/11.
+ * @since 3.4.1
+ */
+@Getter
+public class MapperBuilder extends BaseBuilder {
+
+    /**
+     * 自定义继承的Mapper类全称,带包名
+     */
+    private String superClass = ConstVal.SUPER_MAPPER_CLASS;
+
+    public MapperBuilder(StrategyConfig strategyConfig) {
+        super(strategyConfig);
+    }
+
+    /**
+     * 父类Mapper
+     *
+     * @param superClass 类名
+     * @return this
+     */
+    public MapperBuilder superClass(String superClass) {
+        this.superClass = superClass;
+        return this;
+    }
+
+    /**
+     * 父类Mapper
+     *
+     * @param superClass 类
+     * @return this
+     */
+    public MapperBuilder superClass(Class<?> superClass) {
+        return superClass(superClass.getName());
+    }
+
+}

+ 70 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/ServiceBuilder.java

@@ -0,0 +1,70 @@
+package com.baomidou.mybatisplus.generator.config.builder;
+
+import com.baomidou.mybatisplus.generator.config.ConstVal;
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import lombok.Getter;
+
+/**
+ * Service属性配置
+ *
+ * @author nieqiurong 2020/10/11.
+ * @since 3.4.1
+ */
+@Getter
+public class ServiceBuilder extends BaseBuilder {
+
+    /**
+     * 自定义继承的Service类全称,带包名
+     */
+    private String superServiceClass = ConstVal.SUPER_SERVICE_CLASS;
+    /**
+     * 自定义继承的ServiceImpl类全称,带包名
+     */
+    private String superServiceImplClass = ConstVal.SUPER_SERVICE_IMPL_CLASS;
+
+    public ServiceBuilder(StrategyConfig strategyConfig) {
+        super(strategyConfig);
+    }
+
+    /**
+     * Service接口父类
+     *
+     * @param clazz 类
+     * @return this
+     */
+    public ServiceBuilder superServiceClass(Class<?> clazz) {
+        return superServiceClass(clazz.getName());
+    }
+
+    /**
+     * Service接口父类
+     *
+     * @param superServiceClass 类名
+     * @return this
+     */
+    public ServiceBuilder superServiceClass(String superServiceClass) {
+        this.superServiceClass = superServiceClass;
+        return this;
+    }
+
+    /**
+     * Service实现类父类
+     *
+     * @param clazz 类
+     * @return this
+     */
+    public ServiceBuilder superServiceImplClass(Class<?> clazz) {
+        return superServiceImplClass(clazz.getName());
+    }
+
+    /**
+     * Service实现类父类
+     *
+     * @param superServiceImplClass 类名
+     * @return this
+     */
+    public ServiceBuilder superServiceImplClass(String superServiceImplClass) {
+        this.superServiceImplClass = superServiceImplClass;
+        return this;
+    }
+}

+ 3 - 3
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/po/TableField.java

@@ -74,7 +74,7 @@ public class TableField {
     }
 
     protected TableField setConvert(StrategyConfig strategyConfig) {
-        if (strategyConfig.isEntityTableFieldAnnotationEnable() || isKeyWords()) {
+        if (strategyConfig.entity().isTableFieldAnnotationEnable() || isKeyWords()) {
             this.convert = true;
             return this;
         }
@@ -82,7 +82,7 @@ public class TableField {
             this.convert = !name.equalsIgnoreCase(propertyName);
         } else {
             // 转换字段
-            if (NamingStrategy.underline_to_camel == strategyConfig.getColumnNaming()) {
+            if (NamingStrategy.underline_to_camel == strategyConfig.entity().getColumnNaming()) {
                 // 包含大写处理
                 if (StringUtils.containsUpperCase(name)) {
                     this.convert = true;
@@ -117,7 +117,7 @@ public class TableField {
      */
     public TableField setPropertyName(String propertyName, StrategyConfig strategyConfig, IColumnType columnType) {
         this.columnType = columnType;
-        if (strategyConfig.isEntityBooleanColumnRemoveIsPrefix()
+        if (strategyConfig.entity().isBooleanColumnRemoveIsPrefix()
             && "boolean".equalsIgnoreCase(this.getPropertyType()) && propertyName.startsWith("is")) {
             this.convert = true;
             this.propertyName = StringUtils.removePrefixAfterPrefixToLower(propertyName, 2);

+ 7 - 7
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/po/TableInfo.java

@@ -81,7 +81,7 @@ public class TableInfo {
     }
 
     protected TableInfo setConvert(StrategyConfig strategyConfig) {
-        if (strategyConfig.startsWithTablePrefix(name) || strategyConfig.isEntityTableFieldAnnotationEnable()) {
+        if (strategyConfig.startsWithTablePrefix(name) || strategyConfig.entity().isTableFieldAnnotationEnable()) {
             // 包含前缀
             this.convert = true;
         } else if (strategyConfig.isCapitalModeNaming(name)) {
@@ -89,7 +89,7 @@ public class TableInfo {
             this.convert = !entityName.equalsIgnoreCase(name);
         } else {
             // 转换字段
-            if (NamingStrategy.underline_to_camel == strategyConfig.getColumnNaming()) {
+            if (NamingStrategy.underline_to_camel == strategyConfig.entity().getColumnNaming()) {
                 // 包含大写处理
                 if (StringUtils.containsUpperCase(name)) {
                     this.convert = true;
@@ -250,10 +250,10 @@ public class TableInfo {
      */
     public void importPackage(StrategyConfig strategyConfig, GlobalConfig globalConfig) {
         boolean importSerializable = true;
-        if (StringUtils.isNotBlank(strategyConfig.getSuperEntityClass())) {
+        if (StringUtils.isNotBlank(strategyConfig.entity().getSuperClass())) {
             // 自定义父类
             importSerializable = false;
-            this.importPackages.add(strategyConfig.getSuperEntityClass());
+            this.importPackages.add(strategyConfig.entity().getSuperClass());
         } else {
             if (globalConfig.isActiveRecord()) {
                 // 无父类开启 AR 模式
@@ -267,7 +267,7 @@ public class TableInfo {
         if (this.isConvert()) {
             this.importPackages.add(TableName.class.getCanonicalName());
         }
-        if (strategyConfig.getLogicDeleteFieldName() != null && this.isLogicDelete(strategyConfig.getLogicDeleteFieldName())) {
+        if (strategyConfig.entity().getLogicDeleteFieldName() != null && this.isLogicDelete(strategyConfig.entity().getLogicDeleteFieldName())) {
             this.importPackages.add(TableLogic.class.getCanonicalName());
         }
         if (null != globalConfig.getIdType() && this.isHavePrimaryKey()) {
@@ -298,7 +298,7 @@ public class TableInfo {
                 //TODO 好像default的不用处理也行,这个做优化项目.
                 importPackages.add(FieldFill.class.getCanonicalName());
             }
-            String versionFieldName = strategyConfig.getVersionFieldName();
+            String versionFieldName = strategyConfig.entity().getVersionFieldName();
             if (StringUtils.isNotBlank(versionFieldName) && versionFieldName.equals(field.getName())) {
                 this.importPackages.add(Version.class.getCanonicalName());
             }
@@ -313,7 +313,7 @@ public class TableInfo {
      * @since 3.4.1
      */
     public void processTable(StrategyConfig strategyConfig, GlobalConfig globalConfig) {
-        String entityName = strategyConfig.getNameConvert().entityNameConvert(this);
+        String entityName = strategyConfig.entity().getNameConvert().entityNameConvert(this);
         this.setEntityName(strategyConfig, this.getFileName(entityName, globalConfig.getEntityName(), () -> entityName));
         this.mapperName = this.getFileName(entityName, globalConfig.getMapperName(), () -> entityName + ConstVal.MAPPER);
         this.xmlName = this.getFileName(entityName, globalConfig.getXmlName(), () -> entityName + ConstVal.XML);

+ 20 - 20
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/engine/AbstractTemplateEngine.java

@@ -198,21 +198,21 @@ public abstract class AbstractTemplateEngine {
     public Map<String, Object> getObjectMap(TableInfo tableInfo) {
         Map<String, Object> objectMap;
         ConfigBuilder config = getConfigBuilder();
-        if (config.getStrategyConfig().isControllerMappingHyphenStyle()) {
+        if (config.getStrategyConfig().controller().isHyphenStyle()) {
             objectMap = CollectionUtils.newHashMapWithExpectedSize(33);
-            objectMap.put("controllerMappingHyphenStyle", config.getStrategyConfig().isControllerMappingHyphenStyle());
+            objectMap.put("controllerMappingHyphenStyle", config.getStrategyConfig().controller().isHyphenStyle());
             objectMap.put("controllerMappingHyphen", StringUtils.camelToHyphen(tableInfo.getEntityPath()));
         } else {
             objectMap = CollectionUtils.newHashMapWithExpectedSize(31);
         }
-        objectMap.put("restControllerStyle", config.getStrategyConfig().isRestControllerStyle());
+        objectMap.put("restControllerStyle", config.getStrategyConfig().controller().isRestStyle());
         objectMap.put("config", config);
         objectMap.put("package", config.getPackageConfig().getPackageInfo());
         GlobalConfig globalConfig = config.getGlobalConfig();
         objectMap.put("author", globalConfig.getAuthor());
         objectMap.put("idType", globalConfig.getIdType() == null ? null : globalConfig.getIdType().toString());
-        objectMap.put("logicDeleteFieldName", config.getStrategyConfig().getLogicDeleteFieldName());
-        objectMap.put("versionFieldName", config.getStrategyConfig().getVersionFieldName());
+        objectMap.put("logicDeleteFieldName", config.getStrategyConfig().entity().getLogicDeleteFieldName());
+        objectMap.put("versionFieldName", config.getStrategyConfig().entity().getVersionFieldName());
         objectMap.put("activeRecord", globalConfig.isActiveRecord());
         objectMap.put("kotlin", globalConfig.isKotlin());
         objectMap.put("swagger2", globalConfig.isSwagger2());
@@ -222,21 +222,21 @@ public abstract class AbstractTemplateEngine {
         objectMap.put("baseResultMap", globalConfig.isBaseResultMap());
         objectMap.put("baseColumnList", globalConfig.isBaseColumnList());
         objectMap.put("entity", tableInfo.getEntityName());
-        objectMap.put("entitySerialVersionUID", config.getStrategyConfig().isEntitySerialVersionUID());
-        objectMap.put("entityColumnConstant", config.getStrategyConfig().isEntityColumnConstant());
-        objectMap.put("entityBuilderModel", config.getStrategyConfig().isChainModel());
-        objectMap.put("chainModel", config.getStrategyConfig().isChainModel());
-        objectMap.put("entityLombokModel", config.getStrategyConfig().isEntityLombokModel());
-        objectMap.put("entityBooleanColumnRemoveIsPrefix", config.getStrategyConfig().isEntityBooleanColumnRemoveIsPrefix());
-        objectMap.put("superEntityClass", getSuperClassName(config.getStrategyConfig().getSuperEntityClass()));
-        objectMap.put("superMapperClassPackage", config.getStrategyConfig().getSuperMapperClass());
-        objectMap.put("superMapperClass", getSuperClassName(config.getStrategyConfig().getSuperMapperClass()));
-        objectMap.put("superServiceClassPackage", config.getStrategyConfig().getSuperServiceClass());
-        objectMap.put("superServiceClass", getSuperClassName(config.getStrategyConfig().getSuperServiceClass()));
-        objectMap.put("superServiceImplClassPackage", config.getStrategyConfig().getSuperServiceImplClass());
-        objectMap.put("superServiceImplClass", getSuperClassName(config.getStrategyConfig().getSuperServiceImplClass()));
-        objectMap.put("superControllerClassPackage", verifyClassPacket(config.getStrategyConfig().getSuperControllerClass()));
-        objectMap.put("superControllerClass", getSuperClassName(config.getStrategyConfig().getSuperControllerClass()));
+        objectMap.put("entitySerialVersionUID", config.getStrategyConfig().entity().isSerialVersionUID());
+        objectMap.put("entityColumnConstant", config.getStrategyConfig().entity().isColumnConstant());
+        objectMap.put("entityBuilderModel", config.getStrategyConfig().entity().isChain());
+        objectMap.put("chainModel", config.getStrategyConfig().entity().isChain());
+        objectMap.put("entityLombokModel", config.getStrategyConfig().entity().isLombok());
+        objectMap.put("entityBooleanColumnRemoveIsPrefix", config.getStrategyConfig().entity().isBooleanColumnRemoveIsPrefix());
+        objectMap.put("superEntityClass", getSuperClassName(config.getStrategyConfig().entity().getSuperClass()));
+        objectMap.put("superMapperClassPackage", config.getStrategyConfig().mapper().getSuperClass());
+        objectMap.put("superMapperClass", getSuperClassName(config.getStrategyConfig().mapper().getSuperClass()));
+        objectMap.put("superServiceClassPackage", config.getStrategyConfig().service().getSuperServiceClass());
+        objectMap.put("superServiceClass", getSuperClassName(config.getStrategyConfig().service().getSuperServiceClass()));
+        objectMap.put("superServiceImplClassPackage", config.getStrategyConfig().service().getSuperServiceImplClass());
+        objectMap.put("superServiceImplClass", getSuperClassName(config.getStrategyConfig().service().getSuperServiceImplClass()));
+        objectMap.put("superControllerClassPackage", verifyClassPacket(config.getStrategyConfig().controller().getSuperClass()));
+        objectMap.put("superControllerClass", getSuperClassName(config.getStrategyConfig().controller().getSuperClass()));
         return Objects.isNull(config.getInjectionConfig()) ? objectMap : config.getInjectionConfig().prepareObjectMap(objectMap);
     }
 

+ 1 - 1
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/po/TableInfoTest.java

@@ -153,7 +153,7 @@ public class TableInfoTest {
         tableInfo = new TableInfo().setName("user").setHavePrimaryKey(true);
         tableInfo.addFields(new TableField().setName("u_id").setPropertyName(strategyConfig, "uid").setColumnType(DbColumnType.LONG).setKeyFlag(true));
         tableInfo.addFields(new TableField().setName("create_time").setPropertyName(strategyConfig, "createTime").setColumnType(DbColumnType.DATE).setFill(FieldFill.DEFAULT.name()));
-        tableInfo.importPackage(new StrategyConfig().addTableFills(new TableFill("createTime", FieldFill.DEFAULT)), new GlobalConfig());
+        tableInfo.importPackage(new StrategyConfig().entity().addTableFills(new TableFill("createTime", FieldFill.DEFAULT)).build(), new GlobalConfig());
         Assertions.assertEquals(5, tableInfo.getImportPackages().size());
         Assertions.assertTrue(tableInfo.getImportPackages().contains(Date.class.getName()));
         Assertions.assertTrue(tableInfo.getImportPackages().contains(Serializable.class.getName()));

+ 1 - 1
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/MysqlGenerator.java

@@ -108,7 +108,7 @@ public class MysqlGenerator extends GeneratorTest {
                 // .setSuperEntityClass("com.baomidou.demo.TestEntity")
                 // 自定义实体,公共字段
                 .setSuperEntityColumns("test_id")
-                .addTableFills(new TableFill("ASDD_SS", FieldFill.INSERT_UPDATE))
+                .setTableFillList(Collections.singletonList(new TableFill("ASDD_SS", FieldFill.INSERT_UPDATE)))
                 .setEntityBooleanColumnRemoveIsPrefix(true)
             // 自定义 mapper 父类
             // .setSuperMapperClass("com.baomidou.demo.TestMapper")

+ 34 - 1
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/StrategyConfigTest.java

@@ -125,7 +125,7 @@ class StrategyConfigTest {
         strategyConfig.setTableFillList(tableFillList);
         Assertions.assertFalse(strategyConfig.getTableFillList().isEmpty());
         strategyConfig = new StrategyConfig();
-        strategyConfig.addTableFills(tableFill);
+        strategyConfig.entity().addTableFills(tableFill);
         Assertions.assertFalse(strategyConfig.getTableFillList().isEmpty());
     }
 
@@ -229,6 +229,39 @@ class StrategyConfigTest {
         Assertions.assertTrue(new StrategyConfig().setCapitalMode(true).isCapitalModeNaming("NAME"));
     }
 
+    private void builderValidate(StrategyConfig strategyConfig){
+        Assertions.assertTrue(strategyConfig.isSkipView());
+        Assertions.assertTrue(strategyConfig.isChainModel());
+        Assertions.assertTrue(strategyConfig.entity().isChain());
+        Assertions.assertTrue(strategyConfig.isEntityLombokModel());
+        Assertions.assertTrue(strategyConfig.entity().isLombok());
+        Assertions.assertTrue(strategyConfig.isEntitySerialVersionUID());
+        Assertions.assertTrue(strategyConfig.entity().isSerialVersionUID());
+        Assertions.assertTrue(strategyConfig.isControllerMappingHyphenStyle());
+        Assertions.assertTrue(strategyConfig.controller().isHyphenStyle());
+        Assertions.assertTrue(strategyConfig.isRestControllerStyle());
+        Assertions.assertTrue(strategyConfig.controller().isRestStyle());
+        Assertions.assertEquals("com.baomidou.mp.SuperController", strategyConfig.getSuperControllerClass());
+        Assertions.assertEquals("com.baomidou.mp.SuperController", strategyConfig.controller().getSuperClass());
+        Assertions.assertEquals("com.baomidou.mp.SuperMapper", strategyConfig.getSuperMapperClass());
+        Assertions.assertEquals("com.baomidou.mp.SuperMapper", strategyConfig.mapper().getSuperClass());
+    }
+
+    @Test
+    void builderTest() {
+        StrategyConfig strategyConfig;
+        strategyConfig = new StrategyConfig().setCapitalMode(true).setChainModel(true).setSkipView(true).setEntityLombokModel(true)
+            .setEntitySerialVersionUID(true).setControllerMappingHyphenStyle(true).setRestControllerStyle(true)
+            .setSuperControllerClass("com.baomidou.mp.SuperController").setSuperMapperClass("com.baomidou.mp.SuperMapper")
+        ;
+        builderValidate(strategyConfig);
+        strategyConfig = new StrategyConfig.Builder().skipView(true)
+            .entity().chainModel(true).lombok(true).serialVersionUID(true)
+            .controller().superClass("com.baomidou.mp.SuperController").hyphenStyle(true).restStyle(true)
+            .mapper().superClass("com.baomidou.mp.SuperMapper").build();
+        builderValidate(strategyConfig);
+    }
+
     @Data
     static class SuperBean {
 

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio