Browse Source

策略配置构建.

nieqiurong 4 years ago
parent
commit
9f56e79d7b

+ 132 - 87
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java

@@ -17,10 +17,10 @@ package com.baomidou.mybatisplus.generator.config;
 
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.generator.config.builder.BaseBuilder;
-import com.baomidou.mybatisplus.generator.config.builder.ControllerBuilder;
-import com.baomidou.mybatisplus.generator.config.builder.EntityBuilder;
-import com.baomidou.mybatisplus.generator.config.builder.MapperBuilder;
-import com.baomidou.mybatisplus.generator.config.builder.ServiceBuilder;
+import com.baomidou.mybatisplus.generator.config.builder.Controller;
+import com.baomidou.mybatisplus.generator.config.builder.Entity;
+import com.baomidou.mybatisplus.generator.config.builder.Mapper;
+import com.baomidou.mybatisplus.generator.config.builder.Service;
 import com.baomidou.mybatisplus.generator.config.po.LikeTable;
 import com.baomidou.mybatisplus.generator.config.po.TableFill;
 import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
@@ -104,67 +104,107 @@ public class StrategyConfig {
     }
 
     @Getter(AccessLevel.NONE)
-    private final EntityBuilder entityBuilder = new EntityBuilder(this);
+    private final Entity.Builder entityBuilder = new Entity.Builder(this);
 
     @Getter(AccessLevel.NONE)
-    private final ControllerBuilder controllerBuilder = new ControllerBuilder(this);
+    private final Controller.Builder controllerBuilder = new Controller.Builder(this);
 
     @Getter(AccessLevel.NONE)
-    private final MapperBuilder mapperBuilder = new MapperBuilder(this);
+    private final Mapper.Builder mapperBuilder = new Mapper.Builder(this);
 
     @Getter(AccessLevel.NONE)
-    private final ServiceBuilder serviceBuilder = new ServiceBuilder(this);
+    private final Service.Builder serviceBuilder = new Service.Builder(this);
 
     /**
-     * 实体配置
+     * 实体配置构建者
      *
-     * @return 实体配置
+     * @return 实体配置构建者
      * @since 3.4.1
      */
-    public EntityBuilder entity() {
+    public Entity.Builder entityBuilder() {
         return entityBuilder;
     }
 
+    /**
+     * @return 实体配置
+     * @since 3.4.1
+     */
+    public Entity entity() {
+        return entityBuilder.get();
+    }
+
+    /**
+     * 控制器配置构建者
+     *
+     * @return 控制器配置构建者
+     * @since 3.4.1
+     */
+    public Controller.Builder controllerBuilder() {
+        return controllerBuilder;
+    }
+
     /**
      * 控制器配置
      *
      * @return 控制器配置
      * @since 3.4.1
      */
-    public ControllerBuilder controller() {
-        return controllerBuilder;
+    public Controller controller() {
+        return controllerBuilder.get();
+    }
+
+    /**
+     * Mapper配置构建者
+     *
+     * @return Mapper配置构建者
+     * @since 3.4.1
+     */
+    public Mapper.Builder mapperBuilder() {
+        return mapperBuilder;
     }
 
+
     /**
      * Mapper配置
      *
      * @return Mapper配置
      * @since 3.4.1
      */
-    public MapperBuilder mapper() {
-        return mapperBuilder;
+    public Mapper mapper() {
+        return mapperBuilder.get();
     }
 
+
     /**
-     * Service配置
+     * Service配置构建者
      *
-     * @return Service配置
+     * @return Service配置构建者
      * @since 3.4.1
      */
-    public ServiceBuilder service() {
+    public Service.Builder serviceBuilder() {
         return serviceBuilder;
     }
 
 
+    /**
+     * Service配置
+     *
+     * @return Service配置
+     * @since 3.4.1
+     */
+    public Service service() {
+        return serviceBuilder.get();
+    }
+
     /**
      * 获取名称转换实现
      *
      * @return 名称转换
-     * @see EntityBuilder#getNameConvert()
+     * @see Entity#getNameConvert()
      * @deprecated 3.4.1
      */
     public INameConvert getNameConvert() {
-        return entityBuilder.getNameConvert();
+        return entity().getNameConvert();
     }
 
     /**
@@ -172,7 +212,7 @@ public class StrategyConfig {
      *
      * @param nameConvert 名称转换实现
      * @return this
-     * @see EntityBuilder#nameConvert(INameConvert)
+     * @see Entity.Builder#nameConvert(INameConvert)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -185,12 +225,12 @@ public class StrategyConfig {
      * 获取数据库表映射到实体的命名策略
      *
      * @return 命名策略
-     * @see EntityBuilder#getNaming()
+     * @see Entity.Builder#getNaming()
      * @deprecated 3.4.1
      */
     @Deprecated
     public NamingStrategy getNaming() {
-        return entityBuilder.getNaming();
+        return entity().getNaming();
     }
 
     /**
@@ -198,7 +238,7 @@ public class StrategyConfig {
      *
      * @param naming 命名策略
      * @return this
-     * @see EntityBuilder#naming(NamingStrategy)
+     * @see Entity.Builder#naming(NamingStrategy)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -241,12 +281,12 @@ public class StrategyConfig {
      * 获取字段命名策略
      *
      * @return 命名策略
-     * @see EntityBuilder#getColumnNaming()
+     * @see Entity.Builder#getColumnNaming()
      * @deprecated 3.4.1
      */
     @Deprecated
     public NamingStrategy getColumnNaming() {
-        return entityBuilder.getColumnNaming();
+        return entity().getColumnNaming();
     }
 
     /**
@@ -254,6 +294,7 @@ public class StrategyConfig {
      *
      * @param columnNaming 命名策略
      * @return this
+     * @see Entity.Builder#columnNaming(NamingStrategy)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -278,25 +319,25 @@ public class StrategyConfig {
     /**
      * @param fieldName 字段名
      * @return 是否匹配
-     * @see EntityBuilder#matchSuperEntityColumns(String)
+     * @see Entity.Builder#matchSuperEntityColumns(String)
      * @deprecated 3.4.1
      */
     @Deprecated
     public boolean includeSuperEntityColumns(String fieldName) {
         // 公共字段判断忽略大小写【 部分数据库大小写不敏感 】
-        return entityBuilder.matchSuperEntityColumns(fieldName);
+        return entityBuilder.get().matchSuperEntityColumns(fieldName);
     }
 
     /**
      * @param superEntityColumns 父类字段
      * @return this
-     * @see EntityBuilder#addSuperEntityColumns(String...)
+     * @see Entity.Builder#addSuperEntityColumns(String...)
      * @deprecated 3.4.1
      */
     @Deprecated
     public StrategyConfig setSuperEntityColumns(String... superEntityColumns) {
-        this.entityBuilder.getSuperEntityColumns().clear();    //保持语义
-        this.entityBuilder.getSuperEntityColumns().addAll(Arrays.asList(superEntityColumns));
+        this.entityBuilder.get().getSuperEntityColumns().clear();    //保持语义
+        this.entityBuilder.get().getSuperEntityColumns().addAll(Arrays.asList(superEntityColumns));
         return this;
     }
 
@@ -344,7 +385,7 @@ public class StrategyConfig {
      *
      * @param superEntityClass 类全名称
      * @return this
-     * @see EntityBuilder#superClass(String)
+     * @see Entity.Builder#superClass(String)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -357,12 +398,12 @@ public class StrategyConfig {
      * 获取实体父类全名称
      *
      * @return 类全名称
-     * @see EntityBuilder#getSuperClass() ()
+     * @see Entity.Builder#getSuperClass() ()
      * @deprecated 3.4.1
      */
     @Deprecated
     public String getSuperEntityClass() {
-        return entityBuilder.getSuperClass();
+        return entityBuilder.get().getSuperClass();
     }
 
     /**
@@ -376,7 +417,7 @@ public class StrategyConfig {
      *
      * @param clazz 实体父类 Class
      * @return this
-     * @see EntityBuilder#superClass(Class)
+     * @see Entity.Builder#superClass(Class)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -394,8 +435,8 @@ public class StrategyConfig {
      * @param clazz        实体父类 Class
      * @param columnNaming 字段命名策略
      * @return this
-     * @see EntityBuilder#columnNaming(NamingStrategy)
-     * @see EntityBuilder#superClass(Class)
+     * @see Entity.Builder#columnNaming(NamingStrategy)
+     * @see Entity.Builder#superClass(Class)
      * @deprecated 3.4.1 {@link #setSuperEntityClass(Class)} {@link #setColumnNaming(NamingStrategy)}
      */
     @Deprecated
@@ -410,7 +451,7 @@ public class StrategyConfig {
      *
      * @param clazz 类
      * @return this
-     * @see ServiceBuilder#superServiceClass(Class)
+     * @see Service.Builder#superServiceClass(Class)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -424,7 +465,7 @@ public class StrategyConfig {
      *
      * @param superServiceClass 类名
      * @return this
-     * @see ServiceBuilder#superServiceClass(String)
+     * @see Service.Builder#superServiceClass(String)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -437,12 +478,12 @@ public class StrategyConfig {
      * Service接口父类
      *
      * @return Service接口父类
-     * @see ServiceBuilder#getSuperServiceClass()
+     * @see Service.Builder#getSuperServiceClass()
      * @deprecated 3.4.1
      */
     @Deprecated
     public String getSuperServiceClass() {
-        return serviceBuilder.getSuperServiceClass();
+        return service().getSuperServiceClass();
     }
 
     /**
@@ -450,7 +491,7 @@ public class StrategyConfig {
      *
      * @param clazz 类
      * @return this
-     * @see ServiceBuilder#superServiceImplClass(Class)
+     * @see Service.Builder#superServiceImplClass(Class)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -464,7 +505,7 @@ public class StrategyConfig {
      *
      * @param superServiceImplClass 类名
      * @return this
-     * @see ServiceBuilder#superServiceImplClass(Class)
+     * @see Service.Builder#superServiceImplClass(Class)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -477,12 +518,12 @@ public class StrategyConfig {
      * 获取Service实现类父类
      *
      * @return this
-     * @see ServiceBuilder#getSuperServiceImplClass()
+     * @see Service.Builder#getSuperServiceImplClass()
      * @deprecated 3.4.1
      */
     @Deprecated
     public String getSuperServiceImplClass() {
-        return serviceBuilder.getSuperServiceImplClass();
+        return service().getSuperServiceImplClass();
     }
 
     /**
@@ -490,7 +531,7 @@ public class StrategyConfig {
      *
      * @param clazz 父类控制器
      * @return this
-     * @see ControllerBuilder#superClass(String)
+     * @see Controller.Builder#superClass(String)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -504,7 +545,7 @@ public class StrategyConfig {
      *
      * @param superControllerClass 父类控制器
      * @return this
-     * @see ControllerBuilder#superClass(String)
+     * @see Controller.Builder#superClass(String)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -517,23 +558,23 @@ public class StrategyConfig {
      * 获取父类控制器
      *
      * @return 父类控制器
-     * @see ControllerBuilder#getSuperClass()
+     * @see Controller.Builder#getSuperClass()
      * @deprecated 3.4.1
      */
     @Deprecated
     public String getSuperControllerClass() {
-        return controllerBuilder.getSuperClass();
+        return controller().getSuperClass();
     }
 
     /**
      * 是否生成@RestController控制器
      *
      * @return 是否生成
-     * @see ControllerBuilder#isRestStyle()
+     * @see Controller.Builder#isRestStyle()
      */
     @Deprecated
     public boolean isRestControllerStyle() {
-        return controllerBuilder.isRestStyle();
+        return controller().isRestStyle();
     }
 
     /**
@@ -541,7 +582,7 @@ public class StrategyConfig {
      *
      * @param restControllerStyle 是否生成
      * @return this
-     * @see ControllerBuilder#restStyle(boolean)
+     * @see Controller.Builder#restStyle(boolean)
      */
     @Deprecated
     public StrategyConfig setRestControllerStyle(boolean restControllerStyle) {
@@ -553,12 +594,12 @@ public class StrategyConfig {
      * 是否驼峰转连字符
      *
      * @return 是否驼峰转连字符
-     * @see ControllerBuilder#isHyphenStyle()
+     * @see Controller.Builder#isHyphenStyle()
      * @deprecated 3.4.1
      */
     @Deprecated
     public boolean isControllerMappingHyphenStyle() {
-        return controllerBuilder.isHyphenStyle();
+        return controller().isHyphenStyle();
     }
 
     /**
@@ -566,7 +607,7 @@ public class StrategyConfig {
      *
      * @param controllerMappingHyphenStyle 是否驼峰转连字符
      * @return this
-     * @see ControllerBuilder#hyphenStyle(boolean)
+     * @see Controller.Builder#hyphenStyle(boolean)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -579,12 +620,12 @@ public class StrategyConfig {
      * 设置表填充字段
      *
      * @param tableFillList tableFillList
-     * @see EntityBuilder#addTableFills(List)
+     * @see Entity.Builder#addTableFills(List)
      * @deprecated 3.4.1
      */
     @Deprecated
     public StrategyConfig setTableFillList(List<TableFill> tableFillList) {
-        this.entityBuilder.getTableFillList().clear(); //保持语义
+        this.entityBuilder.get().getTableFillList().clear(); //保持语义
         this.entityBuilder.addTableFills(tableFillList.toArray(new TableFill[]{}));
         return this;
     }
@@ -593,12 +634,12 @@ public class StrategyConfig {
      * 获取表填充字段
      *
      * @return 表填充字段
-     * @see EntityBuilder#getTableFillList()
+     * @see Entity.Builder#getTableFillList()
      * @deprecated 3.4.1
      */
     @Deprecated
     public List<TableFill> getTableFillList() {
-        return entityBuilder.getTableFillList();
+        return entityBuilder.get().getTableFillList();
     }
 
     /**
@@ -607,11 +648,12 @@ public class StrategyConfig {
      * </p>
      *
      * @param clazz 实体父类 Class
+     * @see Entity.Builder#convertSuperEntityColumns(Class)
      * @deprecated 3.4.1
      */
     @Deprecated
     protected void convertSuperEntityColumns(Class<?> clazz) {
-        entityBuilder.convertSuperEntityColumns(clazz);
+        entity().convertSuperEntityColumns(clazz);
     }
 
     /**
@@ -639,24 +681,24 @@ public class StrategyConfig {
 
     /**
      * @return 父类字段
-     * @see EntityBuilder#getSuperEntityColumns()
+     * @see Entity.Builder#getSuperEntityColumns()
      * @deprecated 3.4.1
      */
     @Deprecated
     public Set<String> getSuperEntityColumns() {
-        return this.entityBuilder.getSuperEntityColumns();
+        return entity().getSuperEntityColumns();
     }
 
     /**
      * 获取实体是否为链式模型
      *
      * @return 是否为链式模型
-     * @see EntityBuilder#isChain()
+     * @see Entity#isChain()
      * @deprecated 3.4.1
      */
     @Deprecated
     public boolean isChainModel() {
-        return entityBuilder.isChain();
+        return entity().isChain();
     }
 
     /**
@@ -664,7 +706,7 @@ public class StrategyConfig {
      *
      * @param chainModel 链式模型
      * @return this
-     * @see EntityBuilder#chainModel(boolean)
+     * @see Entity.Builder#chainModel(boolean)
      * @deprecated 3.4.1
      */
     public StrategyConfig setChainModel(boolean chainModel) {
@@ -676,17 +718,17 @@ public class StrategyConfig {
      * 实体是否生成serialVersionUID
      *
      * @return 是否生成
-     * @see EntityBuilder#isSerialVersionUID()
+     * @see Entity.Builder#isSerialVersionUID()
      * @deprecated 3.4.1
      */
     public boolean isEntitySerialVersionUID() {
-        return entityBuilder.isSerialVersionUID();
+        return entity().isSerialVersionUID();
     }
 
     /**
      * @param entitySerialVersionUID 是否生成
      * @return this
-     * @see EntityBuilder#serialVersionUID(boolean)
+     * @see Entity.Builder#serialVersionUID(boolean)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -699,11 +741,12 @@ public class StrategyConfig {
      * 是否为lombok模型
      *
      * @return 是否为lombok模型
+     * @see Entity#isLombok()
      * @deprecated 3.4.1
      */
     @Deprecated
     public boolean isEntityLombokModel() {
-        return entityBuilder.isLombok();
+        return entity().isLombok();
     }
 
     /**
@@ -721,12 +764,12 @@ public class StrategyConfig {
      * 是否生成字段常量
      *
      * @return 是否生成字段常量
-     * @see EntityBuilder#isColumnConstant()
+     * @see Entity#isColumnConstant()
      * @deprecated 3.4.1
      */
     @Deprecated
     public boolean isEntityColumnConstant() {
-        return entityBuilder.isColumnConstant();
+        return entity().isColumnConstant();
     }
 
     /**
@@ -734,7 +777,7 @@ public class StrategyConfig {
      *
      * @param entityColumnConstant 是否生成字段常量
      * @return this
-     * @see EntityBuilder#columnConstant(boolean)
+     * @see Entity.Builder#columnConstant(boolean)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -747,12 +790,12 @@ public class StrategyConfig {
      * Boolean类型字段是否移除is前缀
      *
      * @return 是否移除
-     * @see EntityBuilder#isBooleanColumnRemoveIsPrefix()
+     * @see Entity#isBooleanColumnRemoveIsPrefix()
      * @deprecated 3.4.1
      */
     @Deprecated
     public boolean isEntityBooleanColumnRemoveIsPrefix() {
-        return entityBuilder.isBooleanColumnRemoveIsPrefix();
+        return entity().isBooleanColumnRemoveIsPrefix();
     }
 
     /**
@@ -760,7 +803,7 @@ public class StrategyConfig {
      *
      * @param entityBooleanColumnRemoveIsPrefix 是否移除
      * @return this
-     * @see EntityBuilder#booleanColumnRemoveIsPrefix(boolean)
+     * @see Entity.Builder#booleanColumnRemoveIsPrefix(boolean)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -773,12 +816,12 @@ public class StrategyConfig {
      * 生成实体时,是否生成字段注解
      *
      * @return 是否生成
-     * @see EntityBuilder#isTableFieldAnnotationEnable()
+     * @see Entity.Builder#isTableFieldAnnotationEnable()
      * @deprecated 3.4.1
      */
     @Deprecated
     public boolean isEntityTableFieldAnnotationEnable() {
-        return entityBuilder.isTableFieldAnnotationEnable();
+        return entity().isTableFieldAnnotationEnable();
     }
 
     /**
@@ -786,7 +829,7 @@ public class StrategyConfig {
      *
      * @param entityTableFieldAnnotationEnable 是否生成
      * @return this
-     * @see EntityBuilder#tableFieldAnnotationEnable(boolean)
+     * @see Entity.Builder#tableFieldAnnotationEnable(boolean)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -797,12 +840,14 @@ public class StrategyConfig {
 
     /**
      * 乐观锁属性名称
-     * @deprecated 3.4.1
+     *
      * @return 乐观锁属性名称
+     * @see Entity#getVersionFieldName()
+     * @deprecated 3.4.1
      */
     @Deprecated
     public String getVersionFieldName() {
-        return entityBuilder.getVersionFieldName();
+        return entity().getVersionFieldName();
     }
 
     /**
@@ -810,7 +855,7 @@ public class StrategyConfig {
      *
      * @param versionFieldName 乐观锁属性名称
      * @return this
-     * @see EntityBuilder#versionFieldName(String)
+     * @see Entity.Builder#versionFieldName(String)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -823,12 +868,12 @@ public class StrategyConfig {
      * 逻辑删除属性名称
      *
      * @return 逻辑删除属性名称
-     * @see EntityBuilder#getLogicDeleteFieldName()
+     * @see Entity#getLogicDeleteFieldName()
      * @deprecated 3.4.1
      */
     @Deprecated
     public String getLogicDeleteFieldName() {
-        return entityBuilder.getLogicDeleteFieldName();
+        return entity().getLogicDeleteFieldName();
     }
 
     /**
@@ -836,7 +881,7 @@ public class StrategyConfig {
      *
      * @param logicDeleteFieldName 逻辑删除属性名称
      * @return this
-     * @see EntityBuilder#logicDeleteFieldName(String)
+     * @see Entity.Builder#logicDeleteFieldName(String)
      * @deprecated 3.4.1
      */
     @Deprecated
@@ -849,12 +894,12 @@ public class StrategyConfig {
      * 父类Mapper
      *
      * @return 类名
-     * @see MapperBuilder#getSuperClass()
+     * @see Mapper.Builder#getSuperClass()
      * @deprecated 3.4.1
      */
     @Deprecated
     public String getSuperMapperClass() {
-        return mapperBuilder.getSuperClass();
+        return mapper().getSuperClass();
     }
 
     /**
@@ -862,7 +907,7 @@ public class StrategyConfig {
      *
      * @param superMapperClass 类名
      * @return this
-     * @see MapperBuilder#superClass(String)
+     * @see Mapper.Builder#superClass(String)
      * @deprecated 3.4.1
      */
     @Deprecated

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

@@ -5,7 +5,7 @@ import lombok.AccessLevel;
 import lombok.Getter;
 
 /**
- * 基础属性配置
+ * 配置构建
  *
  * @author nieqiurong 2020/10/11.
  * @since 3.4.1
@@ -19,20 +19,20 @@ public class BaseBuilder {
         this.strategyConfig = strategyConfig;
     }
 
-    public EntityBuilder entity() {
-        return strategyConfig.entity();
+    public Entity.Builder entityBuilder() {
+        return strategyConfig.entityBuilder();
     }
 
-    public ControllerBuilder controller() {
-        return strategyConfig.controller();
+    public Controller.Builder controllerBuilder() {
+        return strategyConfig.controllerBuilder();
     }
 
-    public MapperBuilder mapper() {
-        return strategyConfig.mapper();
+    public Mapper.Builder mapperBuilder() {
+        return strategyConfig.mapperBuilder();
     }
 
-    public ServiceBuilder service() {
-        return strategyConfig.service();
+    public Service.Builder serviceBuilder() {
+        return strategyConfig.serviceBuilder();
     }
 
     public StrategyConfig build() {

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

@@ -0,0 +1,93 @@
+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 Controller {
+
+    private Controller() {
+    }
+
+    /**
+     * 生成 <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 static class Builder extends BaseBuilder {
+
+        private final Controller controller = new Controller();
+
+        public Builder(StrategyConfig strategyConfig) {
+            super(strategyConfig);
+        }
+
+        /**
+         * 父类控制器
+         *
+         * @param clazz 父类控制器
+         * @return this
+         */
+        public Builder superClass(Class<?> clazz) {
+            return superClass(clazz.getName());
+        }
+
+        /**
+         * 父类控制器
+         *
+         * @param superClass 父类控制器类名
+         * @return this
+         */
+        public Builder superClass(String superClass) {
+            this.controller.superClass = superClass;
+            return this;
+        }
+
+        /**
+         * 是否驼峰转连字符
+         *
+         * @return this
+         */
+        public Builder hyphenStyle(boolean hyphenStyle) {
+            this.controller.hyphenStyle = hyphenStyle;
+            return this;
+        }
+
+        /**
+         * 生成@RestController控制器
+         *
+         * @param restStyle 是否生成@RestController控制器
+         * @return this
+         */
+        public Builder restStyle(boolean restStyle) {
+            this.controller.restStyle = restStyle;
+            return this;
+        }
+
+        public Controller get() {
+            return this.controller;
+        }
+    }
+}

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

@@ -1,80 +0,0 @@
-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;
-    }
-}

+ 170 - 159
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/EntityBuilder.java → mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/Entity.java

@@ -29,11 +29,10 @@ import java.util.stream.Collectors;
  * @since 3.4.1
  */
 @Getter
-public class EntityBuilder extends BaseBuilder {
+public class Entity {
+
+    private Entity() {
 
-    public EntityBuilder(StrategyConfig strategyConfig) {
-        super(strategyConfig);
-        this.nameConvert = new INameConvert.DefaultNameConvert(strategyConfig);
     }
 
     /**
@@ -117,161 +116,6 @@ public class EntityBuilder extends BaseBuilder {
      */
     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 反射属性转换为公共字段
@@ -326,4 +170,171 @@ public class EntityBuilder extends BaseBuilder {
         return superEntityColumns.stream().anyMatch(e -> e.equalsIgnoreCase(fieldName));
     }
 
+    public static class Builder extends BaseBuilder {
+
+        private final Entity entity = new Entity();
+
+        public Builder(StrategyConfig strategyConfig) {
+            super(strategyConfig);
+            this.entity.nameConvert = new INameConvert.DefaultNameConvert(strategyConfig);
+        }
+
+        /**
+         * 名称转换实现
+         *
+         * @param nameConvert 名称转换实现
+         * @return this
+         */
+        public Builder nameConvert(INameConvert nameConvert) {
+            this.entity.nameConvert = nameConvert;
+            return this;
+        }
+
+        public Builder superClass(Class<?> clazz) {
+            return superClass(clazz.getName());
+        }
+
+        public Builder superClass(String superEntityClass) {
+            this.entity.superClass = superEntityClass;
+            return this;
+        }
+
+        /**
+         * 实体是否生成serialVersionUID
+         *
+         * @param serialVersionUID 是否生成
+         * @return this
+         */
+        public Builder serialVersionUID(boolean serialVersionUID) {
+            this.entity.serialVersionUID = serialVersionUID;
+            return this;
+        }
+
+        /**
+         * 是否生成字段常量
+         *
+         * @param columnConstant 是否生成字段常量
+         * @return this
+         */
+        public Builder columnConstant(boolean columnConstant) {
+            this.entity.columnConstant = columnConstant;
+            return this;
+        }
+
+        /**
+         * 实体是否为链式模型
+         *
+         * @param chain 是否为链式模型
+         * @return this
+         */
+        public Builder chainModel(boolean chain) {
+            this.entity.chain = chain;
+            return this;
+        }
+
+        /**
+         * 是否为lombok模型
+         *
+         * @param lombok 是否为lombok模型
+         * @return this
+         */
+        public Builder lombok(boolean lombok) {
+            this.entity.lombok = lombok;
+            return this;
+        }
+
+        /**
+         * Boolean类型字段是否移除is前缀
+         *
+         * @param booleanColumnRemoveIsPrefix 是否移除
+         * @return this
+         */
+        public Builder booleanColumnRemoveIsPrefix(boolean booleanColumnRemoveIsPrefix) {
+            this.entity.booleanColumnRemoveIsPrefix = booleanColumnRemoveIsPrefix;
+            return this;
+        }
+
+        /**
+         * 生成实体时,是否生成字段注解
+         *
+         * @param tableFieldAnnotationEnable 是否生成
+         * @return this
+         */
+        public Builder tableFieldAnnotationEnable(boolean tableFieldAnnotationEnable) {
+            this.entity.tableFieldAnnotationEnable = tableFieldAnnotationEnable;
+            return this;
+        }
+
+        /**
+         * 乐观锁属性名称
+         *
+         * @param versionFieldName 乐观锁属性名称
+         * @return this
+         */
+        public Builder versionFieldName(String versionFieldName) {
+            this.entity.versionFieldName = versionFieldName;
+            return this;
+        }
+
+        /**
+         * 逻辑删除属性名称
+         *
+         * @param logicDeleteFieldName 逻辑删除属性名称
+         * @return this
+         */
+        public Builder logicDeleteFieldName(String logicDeleteFieldName) {
+            this.entity.logicDeleteFieldName = logicDeleteFieldName;
+            return this;
+        }
+
+        public Builder naming(NamingStrategy namingStrategy) {
+            this.entity.naming = namingStrategy;
+            return this;
+        }
+
+        public Builder columnNaming(NamingStrategy namingStrategy) {
+            this.entity.columnNaming = namingStrategy;
+            return this;
+        }
+
+        /**
+         * 添加父类公共字段
+         *
+         * @param superEntityColumns 父类字段(数据库字段列名)
+         * @return this
+         * @since 3.4.1
+         */
+        public Builder addSuperEntityColumns(String... superEntityColumns) {
+            this.entity.superEntityColumns.addAll(Arrays.asList(superEntityColumns));
+            return this;
+        }
+
+        /**
+         * 添加表字段填充
+         *
+         * @param tableFill 填充字段
+         * @return this
+         * @since 3.4.1
+         */
+        public Builder addTableFills(TableFill... tableFill) {
+            this.entity.tableFillList.addAll(Arrays.asList(tableFill));
+            return this;
+        }
+
+        /**
+         * 添加表字段填充
+         *
+         * @param tableFillList 填充字段集合
+         * @return this
+         * @since 3.4.1
+         */
+        public Builder addTableFills(List<TableFill> tableFillList) {
+            this.entity.tableFillList.addAll(tableFillList);
+            return this;
+        }
+
+        public Entity get(){
+            return this.entity;
+        }
+    }
 }

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

@@ -0,0 +1,58 @@
+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 Mapper {
+
+    private Mapper() {
+    }
+
+    /**
+     * 自定义继承的Mapper类全称,带包名
+     */
+    private String superClass = ConstVal.SUPER_MAPPER_CLASS;
+
+    public static class Builder extends BaseBuilder {
+
+        private final Mapper mapper = new Mapper();
+
+        public Builder(StrategyConfig strategyConfig) {
+            super(strategyConfig);
+        }
+
+        /**
+         * 父类Mapper
+         *
+         * @param superClass 类名
+         * @return this
+         */
+        public Builder superClass(String superClass) {
+            this.mapper.superClass = superClass;
+            return this;
+        }
+
+        /**
+         * 父类Mapper
+         *
+         * @param superClass 类
+         * @return this
+         * @since 3.4.1
+         */
+        public Builder superClass(Class<?> superClass) {
+            return superClass(superClass.getName());
+        }
+
+        public Mapper get() {
+            return this.mapper;
+        }
+    }
+}

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

@@ -1,46 +0,0 @@
-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());
-    }
-
-}

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

@@ -0,0 +1,83 @@
+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 Service {
+
+    private Service() {
+    }
+
+    /**
+     * 自定义继承的Service类全称,带包名
+     */
+    private String superServiceClass = ConstVal.SUPER_SERVICE_CLASS;
+    /**
+     * 自定义继承的ServiceImpl类全称,带包名
+     */
+    private String superServiceImplClass = ConstVal.SUPER_SERVICE_IMPL_CLASS;
+
+
+    public static class Builder extends BaseBuilder {
+
+        private final Service service = new Service();
+
+        public Builder(StrategyConfig strategyConfig) {
+            super(strategyConfig);
+        }
+
+        /**
+         * Service接口父类
+         *
+         * @param clazz 类
+         * @return this
+         */
+        public Builder superServiceClass(Class<?> clazz) {
+            return superServiceClass(clazz.getName());
+        }
+
+        /**
+         * Service接口父类
+         *
+         * @param superServiceClass 类名
+         * @return this
+         */
+        public Builder superServiceClass(String superServiceClass) {
+            this.service.superServiceClass = superServiceClass;
+            return this;
+        }
+
+        /**
+         * Service实现类父类
+         *
+         * @param clazz 类
+         * @return this
+         */
+        public Builder superServiceImplClass(Class<?> clazz) {
+            return superServiceImplClass(clazz.getName());
+        }
+
+        /**
+         * Service实现类父类
+         *
+         * @param superServiceImplClass 类名
+         * @return this
+         */
+        public Builder superServiceImplClass(String superServiceImplClass) {
+            this.service.superServiceImplClass = superServiceImplClass;
+            return this;
+        }
+
+        public Service get() {
+            return this.service;
+        }
+    }
+}

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

@@ -1,70 +0,0 @@
-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;
-    }
-}

+ 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().entity().addTableFills(new TableFill("createTime", FieldFill.DEFAULT)).build(), new GlobalConfig());
+        tableInfo.importPackage(new StrategyConfig().entityBuilder().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()));

+ 5 - 5
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.entity().addTableFills(tableFill);
+        strategyConfig.entityBuilder().addTableFills(tableFill);
         Assertions.assertFalse(strategyConfig.getTableFillList().isEmpty());
     }
 
@@ -242,7 +242,7 @@ class StrategyConfigTest {
         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.SuperController", strategyConfig.controllerBuilder().get().getSuperClass());
         Assertions.assertEquals("com.baomidou.mp.SuperMapper", strategyConfig.getSuperMapperClass());
         Assertions.assertEquals("com.baomidou.mp.SuperMapper", strategyConfig.mapper().getSuperClass());
     }
@@ -256,9 +256,9 @@ class StrategyConfigTest {
         ;
         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();
+            .entityBuilder().chainModel(true).lombok(true).serialVersionUID(true)
+            .controllerBuilder().superClass("com.baomidou.mp.SuperController").hyphenStyle(true).restStyle(true)
+            .mapperBuilder().superClass("com.baomidou.mp.SuperMapper").build();
         builderValidate(strategyConfig);
     }