Browse Source

Merge branch 'develop' into 3.0

nieqiurong 4 years ago
parent
commit
9980dcf764
47 changed files with 968 additions and 4778 deletions
  1. 1 0
      build.gradle
  2. 0 28
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisConfiguration.java
  3. 15 2
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisParameterHandler.java
  4. 15 0
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/handlers/MetaObjectHandler.java
  5. 2 0
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfoHelper.java
  6. 6 1
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/MybatisParameterHandlerTest.java
  7. 67 14
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/AutoGenerator.java
  8. 0 1
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/ConstVal.java
  9. 20 301
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/DataSourceConfig.java
  10. 2 435
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/GlobalConfig.java
  11. 13 0
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/IDbQuery.java
  12. 0 49
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/INameConvert.java
  13. 0 287
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/PackageConfig.java
  14. 136 876
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java
  15. 14 369
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/TemplateConfig.java
  16. 0 56
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/BaseBuilder.java
  17. 543 156
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilder.java
  18. 0 108
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/Controller.java
  19. 0 394
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/Entity.java
  20. 0 129
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/Mapper.java
  21. 0 86
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/PathInfoHandler.java
  22. 0 98
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/Service.java
  23. 1 1
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/po/LikeTable.java
  24. 5 62
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/po/TableField.java
  25. 53 232
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/po/TableInfo.java
  26. 0 259
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/querys/DecoratorDbQuery.java
  27. 8 6
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/rules/NamingStrategy.java
  28. 31 34
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/engine/AbstractTemplateEngine.java
  29. 1 2
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/engine/BeetlTemplateEngine.java
  30. 4 5
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/keywords/BaseKeyWordsHandler.java
  31. 6 6
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/keywords/H2KeyWordsHandler.java
  32. 6 6
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/keywords/MySqlKeyWordsHandler.java
  33. 6 6
      mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/keywords/PostgreSqlKeyWordsHandler.java
  34. 0 48
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/DataSourceConfigTest.java
  35. 0 33
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/GlobalConfigTest.java
  36. 0 41
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/PackageConfigTest.java
  37. 0 107
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/TemplateConfigTest.java
  38. 0 60
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilderTest.java
  39. 0 46
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/po/TableFieldTest.java
  40. 0 195
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/po/TableInfoTest.java
  41. 0 9
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/rules/NamingStrategyTest.java
  42. 0 66
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/engine/TemplateEngineTest.java
  43. 1 3
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/CodeGeneratorTest.java
  44. 1 3
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/CodeGeneratorWithTemplateTest.java
  45. 1 1
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/H2CodeGeneratorTest.java
  46. 6 2
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/MysqlGenerator.java
  47. 4 155
      mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/StrategyConfigTest.java

+ 1 - 0
build.gradle

@@ -185,6 +185,7 @@ subprojects {
     test {
         dependsOn("cleanTest", "generatePomFileForMavenJavaPublication")
         useJUnitPlatform()
+        exclude("**/generator/**")
         exclude("**/mysql/**")
         exclude("**/phoenix/**")
     }

+ 0 - 28
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisConfiguration.java

@@ -198,131 +198,106 @@ public class MybatisConfiguration extends Configuration {
         getLanguageRegistry().setDefaultDriverClass(driver);
     }
 
-    @Override
     public void addKeyGenerator(String id, KeyGenerator keyGenerator) {
         keyGenerators.put(id, keyGenerator);
     }
 
-    @Override
     public Collection<String> getKeyGeneratorNames() {
         return keyGenerators.keySet();
     }
 
-    @Override
     public Collection<KeyGenerator> getKeyGenerators() {
         return keyGenerators.values();
     }
 
-    @Override
     public KeyGenerator getKeyGenerator(String id) {
         return keyGenerators.get(id);
     }
 
-    @Override
     public boolean hasKeyGenerator(String id) {
         return keyGenerators.containsKey(id);
     }
 
-    @Override
     public void addCache(Cache cache) {
         caches.put(cache.getId(), cache);
     }
 
-    @Override
     public Collection<String> getCacheNames() {
         return caches.keySet();
     }
 
-    @Override
     public Collection<Cache> getCaches() {
         return caches.values();
     }
 
-    @Override
     public Cache getCache(String id) {
         return caches.get(id);
     }
 
-    @Override
     public boolean hasCache(String id) {
         return caches.containsKey(id);
     }
 
-    @Override
     public void addResultMap(ResultMap rm) {
         resultMaps.put(rm.getId(), rm);
         checkLocallyForDiscriminatedNestedResultMaps(rm);
         checkGloballyForDiscriminatedNestedResultMaps(rm);
     }
 
-    @Override
     public Collection<String> getResultMapNames() {
         return resultMaps.keySet();
     }
 
-    @Override
     public Collection<ResultMap> getResultMaps() {
         return resultMaps.values();
     }
 
-    @Override
     public ResultMap getResultMap(String id) {
         return resultMaps.get(id);
     }
 
-    @Override
     public boolean hasResultMap(String id) {
         return resultMaps.containsKey(id);
     }
 
-    @Override
     public void addParameterMap(ParameterMap pm) {
         parameterMaps.put(pm.getId(), pm);
     }
 
-    @Override
     public Collection<String> getParameterMapNames() {
         return parameterMaps.keySet();
     }
 
-    @Override
     public Collection<ParameterMap> getParameterMaps() {
         return parameterMaps.values();
     }
 
-    @Override
     public ParameterMap getParameterMap(String id) {
         return parameterMaps.get(id);
     }
 
-    @Override
     public boolean hasParameterMap(String id) {
         return parameterMaps.containsKey(id);
     }
 
-    @Override
     public Map<String, XNode> getSqlFragments() {
         return sqlFragments;
     }
 
-    @Override
     public Collection<String> getMappedStatementNames() {
         buildAllStatements();
         return mappedStatements.keySet();
     }
 
-    @Override
     public Collection<MappedStatement> getMappedStatements() {
         buildAllStatements();
         return mappedStatements.values();
     }
 
-    @Override
     public MappedStatement getMappedStatement(String id) {
         return this.getMappedStatement(id, true);
     }
 
-    @Override
     public MappedStatement getMappedStatement(String id, boolean validateIncompleteStatements) {
         if (validateIncompleteStatements) {
             buildAllStatements();
@@ -330,7 +305,6 @@ public class MybatisConfiguration extends Configuration {
         return mappedStatements.get(id);
     }
 
-    @Override
     public boolean hasStatement(String statementName, boolean validateIncompleteStatements) {
         if (validateIncompleteStatements) {
             buildAllStatements();
@@ -361,7 +335,6 @@ public class MybatisConfiguration extends Configuration {
     }
 
     // Slow but a one time cost. A better solution is welcome.
-    @Override
     protected void checkGloballyForDiscriminatedNestedResultMaps(ResultMap rm) {
         if (rm.hasNestedResultMaps()) {
             for (Map.Entry<String, ResultMap> entry : resultMaps.entrySet()) {
@@ -380,7 +353,6 @@ public class MybatisConfiguration extends Configuration {
     }
 
     // Slow but a one time cost. A better solution is welcome.
-    @Override
     protected void checkLocallyForDiscriminatedNestedResultMaps(ResultMap rm) {
         if (!rm.hasNestedResultMaps() && rm.getDiscriminator() != null) {
             for (Map.Entry<String, String> entry : rm.getDiscriminator().getDiscriminatorMap().entrySet()) {

+ 15 - 2
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisParameterHandler.java

@@ -142,8 +142,21 @@ public class MybatisParameterHandler implements ParameterHandler {
 
     protected void insertFill(MetaObject metaObject, TableInfo tableInfo) {
         GlobalConfigUtils.getMetaObjectHandler(this.configuration).ifPresent(metaObjectHandler -> {
-            if (metaObjectHandler.openInsertFill() && tableInfo.isWithInsertFill()) {
-                metaObjectHandler.insertFill(metaObject);
+            if (metaObjectHandler.openInsertFill()) {
+                if (tableInfo.isWithInsertFill()) {
+                    metaObjectHandler.insertFill(metaObject);
+                } else {
+                    // 兼容旧操作 id类型为input或none的要用填充器处理一下
+                    if (metaObjectHandler.compatibleFillId()) {
+                        String keyProperty = tableInfo.getKeyProperty();
+                        if (StringUtils.isNotBlank(keyProperty)) {
+                            Object value = metaObject.getValue(keyProperty);
+                            if (value == null && (IdType.NONE == tableInfo.getIdType() || IdType.INPUT == tableInfo.getIdType())) {
+                                metaObjectHandler.insertFill(metaObject);
+                            }
+                        }
+                    }
+                }
             }
         });
     }

+ 15 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/handlers/MetaObjectHandler.java

@@ -44,6 +44,21 @@ public interface MetaObjectHandler {
         return true;
     }
 
+    /**
+     * 兼容填充主键判断开关
+     * 如果启用开关:当主键值为空且主键生成策略为NONE或INPUT会进入新增填充
+     * 这开关主要是用来兼容旧版本的用户使用插入填充来进行主键填充的开关
+     * 暂时不确定什么时候会移出此开关,请尽快使用新的Id生成策略来生成Id
+     *
+     * @return 是否启用
+     * @since 3.3.0
+     * @deprecated 3.3.2
+     */
+    @Deprecated
+    default boolean compatibleFillId() {
+        return false;
+    }
+
     /**
      * 是否开启了更新填充
      */

+ 2 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfoHelper.java

@@ -274,6 +274,7 @@ public class TableInfoHelper {
         /* 数据库全局配置 */
         GlobalConfig.DbConfig dbConfig = globalConfig.getDbConfig();
         ReflectorFactory reflectorFactory = tableInfo.getConfiguration().getReflectorFactory();
+        //TODO @咩咩 有空一起来撸完这反射模块.
         Reflector reflector = reflectorFactory.findForClass(clazz);
         List<Field> list = getAllFields(clazz);
         // 标记是否读取到主键
@@ -489,6 +490,7 @@ public class TableInfoHelper {
             throw new IllegalArgumentException("not configure IKeyGenerator implementation class.");
         }
         Configuration configuration = builderAssistant.getConfiguration();
+        //TODO 这里不加上builderAssistant.getCurrentNamespace()的会导致com.baomidou.mybatisplus.core.parser.SqlParserHelper.getSqlParserInfo越(chu)界(gui)
         String id = builderAssistant.getCurrentNamespace() + StringPool.DOT + baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
         ResultMap resultMap = new ResultMap.Builder(builderAssistant.getConfiguration(), id, tableInfo.getKeyType(), new ArrayList<>()).build();
         MappedStatement mappedStatement = new MappedStatement.Builder(builderAssistant.getConfiguration(), id,

+ 6 - 1
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/MybatisParameterHandlerTest.java

@@ -44,7 +44,6 @@ class MybatisParameterHandlerTest {
 
         private String name;
 
-        @TableField(fill = FieldFill.INSERT)
         private String insertOperator;
 
         @TableField(fill = FieldFill.UPDATE)
@@ -66,6 +65,12 @@ class MybatisParameterHandlerTest {
         BoundSql boundSql = mock(BoundSql.class);
         StaticSqlSource staticSqlSource = mock(StaticSqlSource.class);
         GlobalConfigUtils.getGlobalConfig(configuration).setIdentifierGenerator(new DefaultIdentifierGenerator()).setMetaObjectHandler(new MetaObjectHandler() {
+
+            @Override
+            public boolean compatibleFillId() {
+                return true;
+            }
+
             @Override
             public void insertFill(MetaObject metaObject) {
                 setFieldValByName("id", 666L, metaObject);

+ 67 - 14
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/AutoGenerator.java

@@ -15,17 +15,30 @@
  */
 package com.baomidou.mybatisplus.generator;
 
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
 import com.baomidou.mybatisplus.generator.config.*;
 import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
+import com.baomidou.mybatisplus.generator.config.po.TableField;
 import com.baomidou.mybatisplus.generator.config.po.TableInfo;
 import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
 import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
+import lombok.AccessLevel;
 import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
 import lombok.experimental.Accessors;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.Serializable;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 生成文件
@@ -45,6 +58,8 @@ public class AutoGenerator {
     /**
      * 注入配置
      */
+    @Getter(AccessLevel.NONE)
+    @Setter(AccessLevel.NONE)
     protected InjectionConfig injectionConfig;
     /**
      * 数据源配置
@@ -116,26 +131,64 @@ public class AutoGenerator {
             injectionConfig.initMap();
             config.setInjectionConfig(injectionConfig);
         }
-        return config;
+        /*
+         * 表信息列表
+         */
+        List<TableInfo> tableList = this.getAllTableInfoList(config);
+        for (TableInfo tableInfo : tableList) {
+            /* ---------- 添加导入包 ---------- */
+            if (config.getGlobalConfig().isActiveRecord()) {
+                // 开启 ActiveRecord 模式
+                tableInfo.setImportPackages(Model.class.getCanonicalName());
+            }
+            if (tableInfo.isConvert()) {
+                // 表注解
+                tableInfo.setImportPackages(TableName.class.getCanonicalName());
+            }
+            if (config.getStrategyConfig().getLogicDeleteFieldName() != null && tableInfo.isLogicDelete(config.getStrategyConfig().getLogicDeleteFieldName())) {
+                // 逻辑删除注解
+                tableInfo.setImportPackages(TableLogic.class.getCanonicalName());
+            }
+            if (StringUtils.isNotBlank(config.getStrategyConfig().getVersionFieldName())) {
+                // 乐观锁注解
+                tableInfo.setImportPackages(Version.class.getCanonicalName());
+            }
+            boolean importSerializable = true;
+            if (StringUtils.isNotBlank(config.getStrategyConfig().getSuperEntityClass())) {
+                // 父实体
+                tableInfo.setImportPackages(config.getStrategyConfig().getSuperEntityClass());
+                importSerializable = false;
+            }
+            if (config.getGlobalConfig().isActiveRecord()) {
+                importSerializable = true;
+            }
+            if (importSerializable) {
+                tableInfo.setImportPackages(Serializable.class.getCanonicalName());
+            }
+            // Boolean类型is前缀处理
+            if (config.getStrategyConfig().isEntityBooleanColumnRemoveIsPrefix()
+                && CollectionUtils.isNotEmpty(tableInfo.getFields())) {
+                List<TableField> tableFields = tableInfo.getFields().stream().filter(field -> "boolean".equalsIgnoreCase(field.getPropertyType()))
+                    .filter(field -> field.getPropertyName().startsWith("is")).collect(Collectors.toList());
+                tableFields.forEach(field -> {
+                    //主键为is的情况基本上是不存在的.
+                    if (field.isKeyFlag()) {
+                        tableInfo.setImportPackages(TableId.class.getCanonicalName());
+                    } else {
+                        tableInfo.setImportPackages(com.baomidou.mybatisplus.annotation.TableField.class.getCanonicalName());
+                    }
+                    field.setConvert(true);
+                    field.setPropertyName(StringUtils.removePrefixAfterPrefixToLower(field.getPropertyName(), 2));
+                });
+            }
+        }
+        return config.setTableInfoList(tableList);
     }
 
-    /**
-     * @return this
-     * @see #getInjectionConfig()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public InjectionConfig getCfg() {
         return injectionConfig;
     }
 
-    /**
-     * @param injectionConfig injectionConfig
-     * @return this
-     * @see #setInjectionConfig(InjectionConfig)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public AutoGenerator setCfg(InjectionConfig injectionConfig) {
         this.injectionConfig = injectionConfig;
         return this;

+ 0 - 1
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/ConstVal.java

@@ -53,7 +53,6 @@ public interface ConstVal {
 
     String TEMPLATE_ENTITY_JAVA = "/templates/entity.java";
     String TEMPLATE_ENTITY_KT = "/templates/entity.kt";
-    String TEMPLATE_ENTITY = "/templates/entity";
     String TEMPLATE_MAPPER = "/templates/mapper.java";
     String TEMPLATE_XML = "/templates/mapper.xml";
     String TEMPLATE_SERVICE = "/templates/service.java";

+ 20 - 301
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/DataSourceConfig.java

@@ -17,16 +17,13 @@ package com.baomidou.mybatisplus.generator.config;
 
 import com.baomidou.mybatisplus.annotation.DbType;
 import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
 import com.baomidou.mybatisplus.generator.config.converts.TypeConverts;
 import com.baomidou.mybatisplus.generator.config.querys.DbQueryRegistry;
-import com.baomidou.mybatisplus.generator.config.querys.DecoratorDbQuery;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
 import java.sql.Connection;
-import java.sql.Driver;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.Optional;
@@ -50,7 +47,7 @@ public class DataSourceConfig {
      */
     private DbType dbType;
     /**
-     * schemaName
+     * PostgreSQL schemaName
      */
     private String schemaName;
     /**
@@ -80,142 +77,6 @@ public class DataSourceConfig {
      */
     private String password;
 
-    /**
-     * 后续不再公开次构造方法
-     *
-     * @see Builder#Builder(String, String, String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public DataSourceConfig() {
-    }
-
-    /**
-     * 设置表数据查询实现类
-     *
-     * @param dbQuery 表数据查询
-     * @return this
-     * @see Builder#dbQuery(IDbQuery)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public DataSourceConfig setDbQuery(IDbQuery dbQuery) {
-        this.dbQuery = dbQuery;
-        return this;
-    }
-
-    /**
-     * 设置数据库类型
-     *
-     * @param dbType 数据库类型
-     * @return this
-     * @see Builder#dbType(DbType)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public DataSourceConfig setDbType(DbType dbType) {
-        this.dbType = dbType;
-        return this;
-    }
-
-    /**
-     * 设置数据库schema
-     *
-     * @param schemaName 指定schema
-     * @return this
-     * @see Builder#schema(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public DataSourceConfig setSchemaName(String schemaName) {
-        this.schemaName = schemaName;
-        return this;
-    }
-
-    /**
-     * 设置数据库字段转换实现
-     *
-     * @param typeConvert 数据库字段转换实现
-     * @return this
-     * @see Builder#typeConvert(ITypeConvert)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public DataSourceConfig setTypeConvert(ITypeConvert typeConvert) {
-        this.typeConvert = typeConvert;
-        return this;
-    }
-
-    /**
-     * 设置关键字处理器
-     *
-     * @param keyWordsHandler 关键字处理器
-     * @return this
-     * @see Builder#keyWordsHandler(IKeyWordsHandler)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public DataSourceConfig setKeyWordsHandler(IKeyWordsHandler keyWordsHandler) {
-        this.keyWordsHandler = keyWordsHandler;
-        return this;
-    }
-
-    /**
-     * 设置数据库连接地址
-     *
-     * @param url 数据库连接地址
-     * @return this
-     * @see Builder#Builder(java.lang.String, java.lang.String, java.lang.String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public DataSourceConfig setUrl(String url) {
-        this.url = url;
-        return this;
-    }
-
-    /**
-     * 设置驱动名称
-     *
-     * @param driverName 驱动名
-     * @return this
-     * @see Builder#driver(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public DataSourceConfig setDriverName(String driverName) {
-        this.driverName = driverName;
-        return this;
-    }
-
-    /**
-     * 设置数据库账号
-     *
-     * @param username 数据库账号
-     * @return this
-     * @see Builder#Builder(java.lang.String, java.lang.String, java.lang.String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public DataSourceConfig setUsername(String username) {
-        this.username = username;
-        return this;
-    }
-
-    /**
-     * 设置数据库密码
-     *
-     * @param password 数据库密码
-     * @return this
-     * @see Builder#Builder(java.lang.String, java.lang.String, java.lang.String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public DataSourceConfig setPassword(String password) {
-        this.password = password;
-        return this;
-    }
-
     public IDbQuery getDbQuery() {
         if (null == dbQuery) {
             DbType dbType = getDbType();
@@ -234,9 +95,9 @@ public class DataSourceConfig {
      */
     public DbType getDbType() {
         if (null == this.dbType) {
-            this.dbType = this.getDbType(this.url.toLowerCase());
+            this.dbType = this.getDbType(this.driverName);
             if (null == this.dbType) {
-                this.dbType = this.getDbType(this.driverName);
+                this.dbType = this.getDbType(this.url.toLowerCase());
                 if (null == this.dbType) {
                     throw ExceptionUtils.mpe("Unknown type of database!");
                 }
@@ -253,33 +114,34 @@ public class DataSourceConfig {
      * @return 类型枚举值,如果没找到,则返回 null
      */
     private DbType getDbType(String str) {
-        if (url.contains(":mysql:") || url.contains(":cobar:")) {
+        if (str.contains("mysql")) {
             return DbType.MYSQL;
-        } else if (str.contains(":oracle:")) {
+        } else if (str.contains("oracle")) {
             return DbType.ORACLE;
-        } else if (str.contains(":postgresql:")) {
+        } else if (str.contains("postgresql")) {
             return DbType.POSTGRE_SQL;
-        } else if (str.contains(":sqlserver:")) {
+        } else if (str.contains("sqlserver")) {
             return DbType.SQL_SERVER;
-        } else if (str.contains(":db2:")) {
+        } else if (str.contains("db2")) {
             return DbType.DB2;
-        } else if (str.contains(":mariadb:")) {
+        } else if (str.contains("mariadb")) {
             return DbType.MARIADB;
-        } else if (str.contains(":sqlite:")) {
+        } else if (str.contains("sqlite")) {
             return DbType.SQLITE;
-        } else if (str.contains(":h2:")) {
+        } else if (str.contains("h2")) {
             return DbType.H2;
-        } else if (str.contains(":kingbase:") || str.contains(":kingbase8:")) {
+        } else if (str.contains("kingbase") || str.contains("kingbase8")) {
             return DbType.KINGBASE_ES;
-        } else if (str.contains(":dm:")) {
+        } else if (str.contains("dm")) {
             return DbType.DM;
-        } else if (str.contains(":zenith:")) {
+        } else if (str.contains("zenith")) {
             return DbType.GAUSS;
-        } else if (str.contains(":oscar:")) {
+        } else if (str.contains("oscar")) {
             return DbType.OSCAR;
-        } else if (str.contains(":firebird:")) {
+        } else if (str.contains("firebird")) {
             return DbType.FIREBIRD;
-        } else {
+        }
+        else {
             return DbType.OTHER;
         }
     }
@@ -298,160 +160,17 @@ public class DataSourceConfig {
 
     /**
      * 创建数据库连接对象
-     * 这方法建议只调用一次,毕竟只是代码生成,用一个连接就行。
      *
      * @return Connection
-     * @see DecoratorDbQuery#getConnection()
      */
     public Connection getConn() {
         Connection conn;
         try {
-            if (StringUtils.isNotBlank(this.driverName)) {
-                Class.forName(this.driverName);
-            }
-            conn = DriverManager.getConnection(this.url, this.username, this.password);
-            String schema = StringUtils.isNotBlank(this.schemaName) ? this.schemaName : getDefaultSchema();
-            if (StringUtils.isNotBlank(schema)) {
-                this.schemaName = schema;
-                conn.setSchema(schema);
-            }
+            Class.forName(driverName);
+            conn = DriverManager.getConnection(url, username, password);
         } catch (ClassNotFoundException | SQLException e) {
             throw new RuntimeException(e);
         }
         return conn;
     }
-
-    /**
-     * 获取数据库默认schema
-     *
-     * @return 默认schema
-     * @since 3.4.1
-     */
-    private String getDefaultSchema() {
-        DbType dbType = getDbType();
-        String schema = null;
-        if (DbType.POSTGRE_SQL == dbType) {
-            //pg 默认 schema=public
-            schema = "public";
-        } else if (DbType.KINGBASE_ES == dbType) {
-            //kingbase 默认 schema=PUBLIC
-            schema = "PUBLIC";
-        } else if (DbType.DB2 == dbType) {
-            //db2 默认 schema=current schema
-            schema = "current schema";
-        } else if (DbType.ORACLE == dbType) {
-            //oracle 默认 schema=username
-            schema = this.username.toUpperCase();
-        }
-        return schema;
-    }
-
-    /**
-     * 数据库配置构建者
-     *
-     * @author nieqiurong 2020/10/10.
-     * @since 3.4.1
-     */
-    public static class Builder {
-
-        private final DataSourceConfig dataSourceConfig = new DataSourceConfig();
-
-        /**
-         * 构造初始化方法
-         *
-         * @param url      数据库连接地址
-         * @param username 数据库账号
-         * @param password 数据库密码
-         */
-        public Builder(String url, String username, String password) {
-            this.dataSourceConfig.url = url;
-            this.dataSourceConfig.username = username;
-            this.dataSourceConfig.password = password;
-        }
-
-        /**
-         * 设置数据库查询实现
-         *
-         * @param dbQuery 数据库查询实现
-         * @return this
-         */
-        public Builder dbQuery(IDbQuery dbQuery) {
-            this.dataSourceConfig.dbQuery = dbQuery;
-            return this;
-        }
-
-        /**
-         * 设置数据库类型
-         *
-         * @param dbType 数据库类型
-         * @return this
-         */
-        public Builder dbType(DbType dbType) {
-            this.dataSourceConfig.dbType = dbType;
-            return this;
-        }
-
-        /**
-         * 设置数据库schema
-         *
-         * @param schemaName 数据库schema
-         * @return this
-         */
-        public Builder schema(String schemaName) {
-            this.dataSourceConfig.schemaName = schemaName;
-            return this;
-        }
-
-        /**
-         * 设置数据库驱动
-         *
-         * @param driverName 驱动名
-         * @return this
-         */
-        public Builder driver(String driverName) {
-            this.dataSourceConfig.driverName = driverName;
-            return this;
-        }
-
-        /**
-         * 设置数据库驱动
-         *
-         * @param driver 驱动类
-         * @return this
-         */
-        public Builder driver(Class<? extends Driver> driver) {
-            return driver(driver.getName());
-        }
-
-        /**
-         * 设置类型转换器
-         *
-         * @param typeConvert 类型转换器
-         * @return this
-         */
-        public Builder typeConvert(ITypeConvert typeConvert) {
-            this.dataSourceConfig.typeConvert = typeConvert;
-            return this;
-        }
-
-        /**
-         * 设置数据库关键字处理器
-         *
-         * @param keyWordsHandler 关键字处理器
-         * @return this
-         */
-        public Builder keyWordsHandler(IKeyWordsHandler keyWordsHandler) {
-            this.dataSourceConfig.keyWordsHandler = keyWordsHandler;
-            return this;
-        }
-
-        /**
-         * 构建数据库配置
-         *
-         * @return 数据库配置
-         */
-        public DataSourceConfig build() {
-            return this.dataSourceConfig;
-        }
-    }
 }

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

@@ -16,8 +16,6 @@
 package com.baomidou.mybatisplus.generator.config;
 
 import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.generator.config.builder.Entity;
-import com.baomidou.mybatisplus.generator.config.builder.Mapper;
 import com.baomidou.mybatisplus.generator.config.rules.DateType;
 
 import lombok.Data;
@@ -34,9 +32,9 @@ import lombok.experimental.Accessors;
 public class GlobalConfig {
 
     /**
-     * 生成文件的输出目录【 windows:D://  linux or mac:/tmp 
+     * 生成文件的输出目录【默认 D 盘根目录
      */
-    private String outputDir = System.getProperty("os.name").toLowerCase().contains("windows") ? "D://" : "/tmp";
+    private String outputDir = "D://";
 
     /**
      * 是否覆盖已有文件
@@ -51,7 +49,6 @@ public class GlobalConfig {
     /**
      * 是否在xml中添加二级缓存配置
      */
-    @Deprecated
     private boolean enableCache = false;
 
     /**
@@ -72,13 +69,11 @@ public class GlobalConfig {
     /**
      * 开启 ActiveRecord 模式
      */
-    @Deprecated
     private boolean activeRecord = false;
 
     /**
      * 开启 BaseResultMap
      */
-    @Deprecated
     private boolean baseResultMap = false;
 
     /**
@@ -89,7 +84,6 @@ public class GlobalConfig {
     /**
      * 开启 baseColumnList
      */
-    @Deprecated
     private boolean baseColumnList = false;
     /**
      * 各层文件名称方式,例如: %sAction 生成 UserAction
@@ -101,435 +95,8 @@ public class GlobalConfig {
     private String serviceName;
     private String serviceImplName;
     private String controllerName;
-
-    /**
-     * 后续不再公开此构造方法
-     *
-     * @see Builder
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig() {
-    }
-
     /**
      * 指定生成的主键的ID类型
      */
-    @Deprecated
     private IdType idType;
-
-    /**
-     * 是否开启 ActiveRecord 模式
-     *
-     * @return 是否开启
-     * @see Entity#isActiveRecord()
-     * @deprecated 3.4.1
-     */
-    public boolean isActiveRecord() {
-        return activeRecord;
-    }
-
-    /**
-     * 开启 ActiveRecord 模式
-     *
-     * @param activeRecord 是否开启
-     * @return this
-     * @see com.baomidou.mybatisplus.generator.config.builder.Entity.Builder#activeRecord(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setActiveRecord(boolean activeRecord) {
-        this.activeRecord = activeRecord;
-        return this;
-    }
-
-    /**
-     * @return this
-     * @see Entity#getIdType()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public IdType getIdType() {
-        return idType;
-    }
-
-    /**
-     * 指定生成的主键的ID类型
-     *
-     * @param idType 主键类型
-     * @return this
-     * @see Entity.Builder#idType(IdType)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setIdType(IdType idType) {
-        this.idType = idType;
-        return this;
-    }
-
-    /**
-     * @return 是否开启
-     * @see Mapper#isBaseResultMap() a
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public boolean isBaseResultMap() {
-        return baseResultMap;
-    }
-
-    /**
-     * @param baseResultMap 是否开启
-     * @return this
-     * @see Mapper.Builder#baseResultMap(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setBaseResultMap(boolean baseResultMap) {
-        this.baseResultMap = baseResultMap;
-        return this;
-    }
-
-    /**
-     * @return 是否开启
-     * @see Mapper#isBaseColumnList()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public boolean isBaseColumnList() {
-        return baseColumnList;
-    }
-
-    /**
-     * @see Mapper.Builder#baseColumnList(boolean)
-     * @param baseColumnList 是否开启
-     * @return this
-     */
-    @Deprecated
-    public GlobalConfig setBaseColumnList(boolean baseColumnList) {
-        this.baseColumnList = baseColumnList;
-        return this;
-    }
-
-    /**
-     * @return 是否开启
-     * @see Mapper#isEnableXmlCache()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public boolean isEnableCache() {
-        return enableCache;
-    }
-
-    /**
-     * @param enableCache 是否开启
-     * @return this
-     * @see Mapper.Builder#enableXmlCache(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setEnableCache(boolean enableCache) {
-        this.enableCache = enableCache;
-        return this;
-    }
-
-    /**
-     * @param entityName
-     * @return this
-     * @see Builder#entityName(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setEntityName(String entityName) {
-        this.entityName = entityName;
-        return this;
-    }
-
-    /**
-     * @param mapperName
-     * @return this
-     * @see Builder#mapperName(String)
-     * @deprecated 3.4.1
-     */
-    public GlobalConfig setMapperName(String mapperName) {
-        this.mapperName = mapperName;
-        return this;
-    }
-
-    /**
-     * @param xmlName
-     * @return this
-     * @see Builder#xmlName(String)
-     * @deprecated 3.4.1
-     */
-    public GlobalConfig setXmlName(String xmlName) {
-        this.xmlName = xmlName;
-        return this;
-    }
-
-    /**
-     * @param serviceName
-     * @return this
-     * @see Builder#serviceName(String)
-     * @deprecated 3.4.1
-     */
-    public GlobalConfig setServiceName(String serviceName) {
-        this.serviceName = serviceName;
-        return this;
-    }
-
-    /**
-     * @param serviceImplName
-     * @return this
-     * @see Builder#serviceImplName(String)
-     * @deprecated 3.4.1
-     */
-    public GlobalConfig setServiceImplName(String serviceImplName) {
-        this.serviceImplName = serviceImplName;
-        return this;
-    }
-
-    /**
-     * @param controllerName
-     * @return this
-     * @see Builder#controllerName(String)
-     * @deprecated 3.4.1
-     */
-    public GlobalConfig setControllerName(String controllerName) {
-        this.controllerName = controllerName;
-        return this;
-    }
-
-    /**
-     * @param dateType
-     * @return this
-     * @see Builder#dateType(DateType)
-     * @deprecated 3.4.1
-     */
-    public GlobalConfig setDateType(DateType dateType) {
-        this.dateType = dateType;
-        return this;
-    }
-
-    /**
-     * @param outputDir
-     * @return this
-     * @see Builder#outputDir(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setOutputDir(String outputDir) {
-        this.outputDir = outputDir;
-        return this;
-    }
-
-    /**
-     * @param fileOverride
-     * @return this
-     * @see Builder#fileOverride(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setFileOverride(boolean fileOverride) {
-        this.fileOverride = fileOverride;
-        return this;
-    }
-
-    /**
-     * @param open
-     * @return this
-     * @see Builder#openDir(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setOpen(boolean open) {
-        this.open = open;
-        return this;
-    }
-
-    /**
-     * @param author
-     * @return this
-     * @see Builder#author(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setAuthor(String author) {
-        this.author = author;
-        return this;
-    }
-
-    /**
-     * @param kotlin
-     * @return this
-     * @see Builder#kotlin(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setKotlin(boolean kotlin) {
-        this.kotlin = kotlin;
-        return this;
-    }
-
-    /**
-     * @param swagger2
-     * @return this
-     * @see Builder#swagger2(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public GlobalConfig setSwagger2(boolean swagger2) {
-        this.swagger2 = swagger2;
-        return this;
-    }
-
-
-    /**
-     * 全局配置构建
-     *
-     * @author nieqiurong 2020/10/11.
-     * @since 3.4.1
-     */
-    public static class Builder {
-
-        private final GlobalConfig globalConfig = new GlobalConfig();
-
-        /**
-         * 开启 ActiveRecord 模式
-         *
-         * @param activeRecord 是否开启
-         * @return this
-         * @see com.baomidou.mybatisplus.generator.config.builder.Entity.Builder#activeRecord(boolean)
-         * @deprecated 3.4.1
-         */
-        @Deprecated
-        public Builder activeRecord(boolean activeRecord) {
-            this.globalConfig.activeRecord = activeRecord;
-            return this;
-        }
-
-        /**
-         * 指定生成的主键的ID类型
-         *
-         * @param idType 主键类型
-         * @return this
-         * @see Entity.Builder#idType(IdType)
-         * @deprecated 3.4.1
-         */
-        @Deprecated
-        public Builder idType(IdType idType) {
-            this.globalConfig.idType = idType;
-            return this;
-        }
-
-        /**
-         * 开启baseResultMap
-         *
-         * @param baseResultMap 是否开启
-         * @return this
-         * @see Mapper.Builder#baseResultMap(boolean)
-         * @deprecated 3.4.1
-         */
-        @Deprecated
-        public Builder baseResultMap(boolean baseResultMap) {
-            this.globalConfig.baseResultMap = baseResultMap;
-            return this;
-        }
-
-        /**
-         * 开启baseColumnList
-         *
-         * @param baseColumnList 是否开启
-         * @return this
-         * @see Mapper.Builder#baseColumnList(boolean)
-         * @deprecated 3.4.1
-         */
-        @Deprecated
-        public Builder baseColumnList(boolean baseColumnList) {
-            this.globalConfig.baseColumnList = baseColumnList;
-            return this;
-        }
-
-        /**
-         * xml中添加二级缓存配置
-         *
-         * @param enableCache 是否开启
-         * @return this
-         * @see Mapper.Builder#enableXmlCache(boolean)
-         * @deprecated 3.4.1
-         */
-        @Deprecated
-        public Builder enableCache(boolean enableCache) {
-            this.globalConfig.enableCache = enableCache;
-            return this;
-        }
-
-        public Builder fileOverride(boolean fileOverride) {
-            this.globalConfig.fileOverride = fileOverride;
-            return this;
-        }
-
-        public Builder openDir(boolean open){
-            this.globalConfig.open = open;
-            return this;
-        }
-
-        public Builder outputDir(String outputDir) {
-            this.globalConfig.outputDir = outputDir;
-            return this;
-        }
-
-        public Builder author(String author){
-            this.globalConfig.author = author;
-            return this;
-        }
-
-        public Builder kotlin(boolean kotlin){
-            this.globalConfig.kotlin = kotlin;
-            return this;
-        }
-
-        public Builder swagger2(boolean swagger2){
-            this.globalConfig.swagger2 = swagger2;
-            return this;
-        }
-
-        public Builder entityName(String entityName){
-            this.globalConfig.entityName = entityName;
-            return this;
-        }
-
-        public Builder xmlName(String xmlName) {
-            this.globalConfig.xmlName = xmlName;
-            return this;
-        }
-
-        public Builder serviceName(String serviceName) {
-            this.globalConfig.serviceName = serviceName;
-            return this;
-        }
-
-        public Builder serviceImplName(String serviceImplName) {
-            this.globalConfig.serviceImplName = serviceImplName;
-            return this;
-        }
-
-        public Builder controllerName(String controllerName) {
-            this.globalConfig.controllerName = controllerName;
-            return this;
-        }
-
-        public Builder mapperName(String mapperName) {
-            this.globalConfig.mapperName = mapperName;
-            return this;
-        }
-
-        public Builder dateType(DateType dateType) {
-            this.globalConfig.dateType = dateType;
-            return this;
-        }
-
-        public GlobalConfig build() {
-            return this.globalConfig;
-        }
-    }
 }

+ 13 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/IDbQuery.java

@@ -18,6 +18,8 @@ package com.baomidou.mybatisplus.generator.config;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import com.baomidou.mybatisplus.annotation.DbType;
+
 /**
  * 表数据查询接口
  *
@@ -26,6 +28,17 @@ import java.sql.SQLException;
  */
 public interface IDbQuery {
 
+    /**
+     * 数据库类型
+     *
+     * @deprecated 3.3.1 {@link DataSourceConfig#setDbType(DbType)}
+     */
+    @Deprecated
+    default DbType dbType() {
+        return null;
+    }
+
+
     /**
      * 表信息查询 SQL
      */

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

@@ -17,9 +17,6 @@ package com.baomidou.mybatisplus.generator.config;
 
 import com.baomidou.mybatisplus.generator.config.po.TableField;
 import com.baomidou.mybatisplus.generator.config.po.TableInfo;
-import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
-
-import java.util.Set;
 
 /**
  * 名称转换接口类
@@ -44,50 +41,4 @@ public interface INameConvert {
      * @return
      */
     String propertyNameConvert(TableField field);
-
-
-    /**
-     * 默认名称转换接口类
-     *
-     * @author nieqiurong 2020/9/20.
-     * @since 3.4.1
-     */
-    class DefaultNameConvert implements INameConvert {
-
-        private final StrategyConfig strategyConfig;
-
-        public DefaultNameConvert(StrategyConfig strategyConfig) {
-            this.strategyConfig = strategyConfig;
-        }
-
-        @Override
-        public String entityNameConvert(TableInfo tableInfo) {
-            return NamingStrategy.capitalFirst(processName(tableInfo.getName(), strategyConfig.entity().getNaming(), strategyConfig.getTablePrefix()));
-        }
-
-        @Override
-        public String propertyNameConvert(TableField field) {
-            return processName(field.getName(), strategyConfig.entity().getNaming(), strategyConfig.getTablePrefix());
-        }
-
-        private String processName(String name, NamingStrategy strategy, Set<String> prefix) {
-            String propertyName;
-            if (prefix.size() > 0) {
-                if (strategy == NamingStrategy.underline_to_camel) {
-                    // 删除前缀、下划线转驼峰
-                    propertyName = NamingStrategy.removePrefixAndCamel(name, prefix);
-                } else {
-                    // 删除前缀
-                    propertyName = NamingStrategy.removePrefix(name, prefix);
-                }
-            } else if (strategy == NamingStrategy.underline_to_camel) {
-                // 下划线转驼峰
-                propertyName = NamingStrategy.underlineToCamel(name);
-            } else {
-                // 不处理
-                propertyName = name;
-            }
-            return propertyName;
-        }
-    }
 }

+ 0 - 287
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/PackageConfig.java

@@ -21,8 +21,6 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -73,13 +71,6 @@ public class PackageConfig {
      */
     private Map<String, String> pathInfo;
 
-    /**
-     * 包配置信息
-     *
-     * @since 3.4.1
-     */
-    private final Map<String, String> packageInfo = new HashMap<>();
-
     /**
      * 父包名
      */
@@ -89,282 +80,4 @@ public class PackageConfig {
         }
         return parent;
     }
-
-
-    /**
-     * 连接父子包名
-     *
-     * @return 连接后的包名
-     * @since 3.4.1
-     */
-    public String joinPackage(String subPackage) {
-        String parent = getParent();
-        return StringUtils.isBlank(parent) ? subPackage : (parent + StringPool.DOT + subPackage);
-    }
-
-    /**
-     * 获取包配置信息
-     *
-     * @return 包配置信息
-     * @since 3.4.1
-     */
-    public Map<String, String> getPackageInfo() {
-        if (packageInfo.isEmpty()) {
-            packageInfo.put(ConstVal.MODULE_NAME, this.getModuleName());
-            packageInfo.put(ConstVal.ENTITY, this.joinPackage(this.getEntity()));
-            packageInfo.put(ConstVal.MAPPER, this.joinPackage(this.getMapper()));
-            packageInfo.put(ConstVal.XML, this.joinPackage(this.getXml()));
-            packageInfo.put(ConstVal.SERVICE, this.joinPackage(this.getService()));
-            packageInfo.put(ConstVal.SERVICE_IMPL, this.joinPackage(this.getServiceImpl()));
-            packageInfo.put(ConstVal.CONTROLLER, this.joinPackage(this.getController()));
-        }
-        return Collections.unmodifiableMap(this.packageInfo);
-    }
-
-    /**
-     * 后续不再公开此构造方法
-     *
-     * @see Builder
-     * @deprecated 3.4.1
-     */
-    public PackageConfig() {
-    }
-
-    /**
-     * @param parent 父包名
-     * @return this
-     * @see Builder#parent(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public PackageConfig setParent(String parent) {
-        this.parent = parent;
-        return this;
-    }
-
-    /**
-     * @param moduleName 模块名
-     * @return this
-     * @see Builder#moduleName(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public PackageConfig setModuleName(String moduleName) {
-        this.moduleName = moduleName;
-        return this;
-    }
-
-    /**
-     * @param entity 实体名
-     * @return this
-     * @see Builder#entity(String)
-     * @deprecated 3.4.1
-     */
-    public PackageConfig setEntity(String entity) {
-        this.entity = entity;
-        return this;
-    }
-
-    /**
-     * @param service service接口包名
-     * @return this
-     * @see Builder#service(String)
-     * @deprecated 3.4.1
-     */
-    public PackageConfig setService(String service) {
-        this.service = service;
-        return this;
-    }
-
-    /**
-     * @param serviceImpl service实现类包名
-     * @return this
-     * @see Builder#serviceImpl(String)
-     * @deprecated 3.4.1
-     */
-    public PackageConfig setServiceImpl(String serviceImpl) {
-        this.serviceImpl = serviceImpl;
-        return this;
-    }
-
-    /**
-     * @param mapper mapper包名
-     * @return this
-     * @see Builder#mapper(String)
-     * @deprecated 3.4.1
-     */
-    public PackageConfig setMapper(String mapper) {
-        this.mapper = mapper;
-        return this;
-    }
-
-    /**
-     * @param xml xml包名
-     * @return this
-     * @see Builder#xml(String)
-     * @deprecated 3.4.1
-     */
-    public PackageConfig setXml(String xml) {
-        this.xml = xml;
-        return this;
-    }
-
-    /**
-     * @param controller 控制器包名
-     * @return this
-     * @see Builder#controller(String)
-     * @deprecated 3.4.1
-     */
-    public PackageConfig setController(String controller) {
-        this.controller = controller;
-        return this;
-    }
-
-    /**
-     * @param pathInfo 路径信息
-     * @return this
-     * @see Builder#pathInfo(Map)
-     * @deprecated 3.4.1
-     */
-    public PackageConfig setPathInfo(Map<String, String> pathInfo) {
-        this.pathInfo = pathInfo;
-        return this;
-    }
-
-    /**
-     * 获取包配置信息
-     *
-     * @param module 模块
-     * @return 配置信息
-     * @since 3.4.1
-     */
-    public String getPackageInfo(String module) {
-        return getPackageInfo().get(module);
-    }
-
-    /**
-     * 构建者
-     *
-     * @author nieqiurong 2020/10/13.
-     * @since 3.4.1
-     */
-    public static class Builder {
-
-        private final PackageConfig packageConfig = new PackageConfig();
-
-        /**
-         * 指定父包名
-         *
-         * @param parent 父包名
-         * @return this
-         */
-        public Builder parent(String parent) {
-            this.packageConfig.parent = parent;
-            return this;
-        }
-
-        /**
-         * 指定模块名称
-         *
-         * @param moduleName 模块名
-         * @return this
-         */
-        public Builder moduleName(String moduleName) {
-            this.packageConfig.moduleName = moduleName;
-            return this;
-        }
-
-        /**
-         * 指定实体包名
-         *
-         * @param entity 实体包名
-         * @return this
-         */
-        public Builder entity(String entity) {
-            this.packageConfig.entity = entity;
-            return this;
-        }
-
-        /**
-         * 指定service接口包名
-         *
-         * @param service service包名
-         * @return this
-         */
-        public Builder service(String service) {
-            this.packageConfig.service = service;
-            return this;
-        }
-
-        /**
-         * service实现类包名
-         *
-         * @param serviceImpl service实现类包名
-         * @return this
-         */
-        public Builder serviceImpl(String serviceImpl) {
-            this.packageConfig.serviceImpl = serviceImpl;
-            return this;
-        }
-
-        /**
-         * 指定mapper接口包名
-         *
-         * @param mapper mapper包名
-         * @return this
-         */
-        public Builder mapper(String mapper) {
-            this.packageConfig.mapper = mapper;
-            return this;
-        }
-
-        /**
-         * 指定xml包名
-         *
-         * @param xml xml包名
-         * @return this
-         */
-        public Builder xml(String xml) {
-            this.packageConfig.xml = xml;
-            return this;
-        }
-
-        /**
-         * 指定控制器包名
-         *
-         * @param controller 控制器包名
-         * @return this
-         */
-        public Builder controller(String controller) {
-            this.packageConfig.controller = controller;
-            return this;
-        }
-
-        /**
-         * 路径配置信息
-         *
-         * @param pathInfo 路径配置信息
-         * @return this
-         */
-        public Builder pathInfo(Map<String, String> pathInfo) {
-            this.packageConfig.pathInfo = pathInfo;
-            return this;
-        }
-
-        /**
-         * 构建包配置对象
-         * <p>当指定{@link #parent(String)} 与 {@link #moduleName(String)}时,其他模块名字会加上这两个作为前缀</p>
-         * <p>
-         * 例如:
-         * <p>当设置 {@link #parent(String)},那么entity的配置为 {@link #getParent()}.{@link #getEntity()}</p>
-         * <p>当设置 {@link #parent(String)}与{@link #moduleName(String)},那么entity的配置为 {@link #getParent()}.{@link #getModuleName()}.{@link #getEntity()} </p>
-         * </p>
-         *
-         * @return 包配置对象
-         */
-        public PackageConfig build() {
-            //TODO 后面考虑把那些entity包名挂到Entity上去
-            return this.packageConfig;
-        }
-    }
 }

+ 136 - 876
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java

@@ -15,25 +15,26 @@
  */
 package com.baomidou.mybatisplus.generator.config;
 
+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.builder.BaseBuilder;
-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;
 import lombok.AccessLevel;
 import lombok.Data;
-import lombok.Getter;
 import lombok.Setter;
 import lombok.experimental.Accessors;
 
+import java.lang.reflect.Field;
 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;
 
 /**
  * 策略配置项
@@ -52,6 +53,19 @@ public class StrategyConfig {
      * 是否跳过视图
      */
     private boolean skipView = false;
+    /**
+     * 名称转换
+     */
+    private INameConvert nameConvert;
+    /**
+     * 数据库表映射到实体的命名策略
+     */
+    private NamingStrategy naming = NamingStrategy.no_change;
+    /**
+     * 数据库表字段映射到实体的命名策略
+     * <p>未指定按照 naming 执行</p>
+     */
+    private NamingStrategy columnNaming = null;
     /**
      * 表前缀
      */
@@ -62,6 +76,32 @@ public class StrategyConfig {
      */
     @Setter(AccessLevel.NONE)
     private final Set<String> fieldPrefix = new HashSet<>();
+    /**
+     * 自定义继承的Entity类全称,带包名
+     */
+    @Setter(AccessLevel.NONE)
+    private String superEntityClass;
+    /**
+     * 自定义基础的Entity类,公共字段
+     */
+    @Setter(AccessLevel.NONE)
+    private final Set<String> superEntityColumns = new HashSet<>();
+    /**
+     * 自定义继承的Mapper类全称,带包名
+     */
+    private String superMapperClass = ConstVal.SUPER_MAPPER_CLASS;
+    /**
+     * 自定义继承的Service类全称,带包名
+     */
+    private String superServiceClass = ConstVal.SUPER_SERVICE_CLASS;
+    /**
+     * 自定义继承的ServiceImpl类全称,带包名
+     */
+    private String superServiceImplClass = ConstVal.SUPER_SERVICE_IMPL_CLASS;
+    /**
+     * 自定义继承的Controller类全称,带包名
+     */
+    private String superControllerClass;
     /**
      * 需要包含的表名,允许正则表达式(与exclude二选一配置)<br/>
      * 当{@link #enableSqlFilter}为true时,正则表达式无效.
@@ -75,177 +115,92 @@ public class StrategyConfig {
     @Setter(AccessLevel.NONE)
     private final Set<String> exclude = new HashSet<>();
     /**
-     * 启用sql过滤,语法不能支持使用sql过滤表的话,可以考虑关闭此开关.
-     *
-     * @since 3.3.1
+     * 实体是否生成 serialVersionUID
      */
-    private boolean enableSqlFilter = true;
+    private boolean entitySerialVersionUID = true;
     /**
-     * 包含表名
-     *
-     * @since 3.3.0
+     * 【实体】是否生成字段常量(默认 false)<br>
+     * -----------------------------------<br>
+     * public static final String ID = "test_id";
      */
-    private LikeTable likeTable;
+    private boolean entityColumnConstant = false;
     /**
-     * 不包含表名
+     * 【实体】是否为构建者模型(默认 false)<br>
+     * -----------------------------------<br>
+     * public User setName(String name) { this.name = name; return this; }
      *
-     * @since 3.3.0
-     */
-    private LikeTable notLikeTable;
-
-    /**
-     * 后续不再公开此构造方法
-     *
-     * @see Builder
-     * @deprecated 3.4.1
+     * @deprecated 3.3.2 {@link #chainModel}
      */
     @Deprecated
-    public StrategyConfig() {
-    }
-
-    @Getter(AccessLevel.NONE)
-    private final Entity.Builder entityBuilder = new Entity.Builder(this);
-
-    @Getter(AccessLevel.NONE)
-    private final Controller.Builder controllerBuilder = new Controller.Builder(this);
-
-    @Getter(AccessLevel.NONE)
-    private final Mapper.Builder mapperBuilder = new Mapper.Builder(this);
-
-    @Getter(AccessLevel.NONE)
-    private final Service.Builder serviceBuilder = new Service.Builder(this);
+    private boolean entityBuilderModel = false;
 
     /**
-     * 实体配置构建者
+     * 【实体】是否为链式模型(默认 false)<br>
+     * -----------------------------------<br>
+     * public User setName(String name) { this.name = name; return this; }
      *
-     * @return 实体配置构建者
-     * @since 3.4.1
+     * @since 3.3.2
      */
-    public Entity.Builder entityBuilder() {
-        return entityBuilder;
-    }
+    private boolean chainModel = false;
 
     /**
-     * @return 实体配置
-     * @since 3.4.1
+     * 【实体】是否为lombok模型(默认 false)<br>
+     * <a href="https://projectlombok.org/">document</a>
      */
-    public Entity entity() {
-        return entityBuilder.get();
-    }
-
+    private boolean entityLombokModel = false;
     /**
-     * 控制器配置构建者
-     *
-     * @return 控制器配置构建者
-     * @since 3.4.1
+     * Boolean类型字段是否移除is前缀(默认 false)<br>
+     * 比如 : 数据库字段名称 : 'is_xxx',类型为 : tinyint. 在映射实体的时候则会去掉is,在实体类中映射最终结果为 xxx
      */
-    public Controller.Builder controllerBuilder() {
-        return controllerBuilder;
-    }
-
+    private boolean entityBooleanColumnRemoveIsPrefix = false;
     /**
-     * 控制器配置
-     *
-     * @return 控制器配置
-     * @since 3.4.1
+     * 生成 <code>@RestController</code> 控制器
+     * <pre>
+     *      <code>@Controller</code> -> <code>@RestController</code>
+     * </pre>
      */
-    public Controller controller() {
-        return controllerBuilder.get();
-    }
-
+    private boolean restControllerStyle = false;
     /**
-     * Mapper配置构建者
-     *
-     * @return Mapper配置构建者
-     * @since 3.4.1
+     * 驼峰转连字符
+     * <pre>
+     *      <code>@RequestMapping("/managerUserActionHistory")</code> -> <code>@RequestMapping("/manager-user-action-history")</code>
+     * </pre>
      */
-    public Mapper.Builder mapperBuilder() {
-        return mapperBuilder;
-    }
-
-
+    private boolean controllerMappingHyphenStyle = false;
     /**
-     * Mapper配置
-     *
-     * @return Mapper配置
-     * @since 3.4.1
+     * 是否生成实体时,生成字段注解
      */
-    public Mapper mapper() {
-        return mapperBuilder.get();
-    }
-
-
+    private boolean entityTableFieldAnnotationEnable = false;
     /**
-     * Service配置构建者
-     *
-     * @return Service配置构建者
-     * @since 3.4.1
+     * 乐观锁属性名称
      */
-    public Service.Builder serviceBuilder() {
-        return serviceBuilder;
-    }
-
-
+    private String versionFieldName;
     /**
-     * Service配置
-     *
-     * @return Service配置
-     * @since 3.4.1
+     * 逻辑删除属性名称
      */
-    public Service service() {
-        return serviceBuilder.get();
-    }
-
+    private String logicDeleteFieldName;
     /**
-     * 获取名称转换实现
-     *
-     * @return 名称转换
-     * @see Entity#getNameConvert()
-     * @deprecated 3.4.1
+     * 表填充字段
      */
-    public INameConvert getNameConvert() {
-        return entity().getNameConvert();
-    }
-
+    private List<TableFill> tableFillList = null;
     /**
-     * 名称转换实现
+     * 启用sql过滤,语法不能支持使用sql过滤表的话,可以考虑关闭此开关.
      *
-     * @param nameConvert 名称转换实现
-     * @return this
-     * @see Entity.Builder#nameConvert(INameConvert)
-     * @deprecated 3.4.1
+     * @since 3.3.1
      */
-    @Deprecated
-    public StrategyConfig setNameConvert(INameConvert nameConvert) {
-        this.entityBuilder.nameConvert(nameConvert);
-        return this;
-    }
-
+    private boolean enableSqlFilter = true;
     /**
-     * 获取数据库表映射到实体的命名策略
+     * 包含表名
      *
-     * @return 命名策略
-     * @see Entity.Builder#getNaming()
-     * @deprecated 3.4.1
+     * @since 3.3.0
      */
-    @Deprecated
-    public NamingStrategy getNaming() {
-        return entity().getNaming();
-    }
-
+    private LikeTable likeTable;
     /**
-     * 设置数据库表映射到实体的命名策略
+     * 不包含表名
      *
-     * @param naming 命名策略
-     * @return this
-     * @see Entity.Builder#naming(NamingStrategy)
-     * @deprecated 3.4.1
+     * @since 3.3.0
      */
-    @Deprecated
-    public StrategyConfig setNaming(NamingStrategy naming) {
-        this.entityBuilder.naming(naming);
-        return this;
-    }
+    private LikeTable notLikeTable;
 
     /**
      * 大写命名、字段符合大写字母数字下划线命名
@@ -264,7 +219,7 @@ public class StrategyConfig {
      */
     @Deprecated
     public boolean containsTablePrefix(String tableName) {
-        return this.tablePrefix.stream().anyMatch(tableName::contains);
+        return getTablePrefix().stream().anyMatch(tableName::contains);
     }
 
     /**
@@ -274,108 +229,40 @@ public class StrategyConfig {
      * @since 3.3.2
      */
     public boolean startsWithTablePrefix(String tableName) {
-        return this.tablePrefix.stream().anyMatch(tableName::startsWith);
+        return getTablePrefix().stream().anyMatch(tableName::startsWith);
     }
 
-    /**
-     * 获取字段命名策略
-     *
-     * @return 命名策略
-     * @see Entity.Builder#getColumnNaming()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public NamingStrategy getColumnNaming() {
-        return entity().getColumnNaming();
-    }
-
-    /**
-     * 设置字段命名策略
-     *
-     * @param columnNaming 命名策略
-     * @return this
-     * @see Entity.Builder#columnNaming(NamingStrategy)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setColumnNaming(NamingStrategy columnNaming) {
-        this.entityBuilder.columnNaming(columnNaming);
-        return this;
+        // 未指定以 naming 策略为准
+        return Optional.ofNullable(columnNaming).orElse(naming);
     }
 
-    /**
-     * @param tablePrefix 表前缀
-     * @return this
-     * @see Builder#addTablePrefix(String...)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setTablePrefix(String... tablePrefix) {
-        this.tablePrefix.clear();   //保持语义
         this.tablePrefix.addAll(Arrays.asList(tablePrefix));
         return this;
     }
 
-    /**
-     * @param fieldName 字段名
-     * @return 是否匹配
-     * @see Entity.Builder#matchSuperEntityColumns(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public boolean includeSuperEntityColumns(String fieldName) {
         // 公共字段判断忽略大小写【 部分数据库大小写不敏感 】
-        return entityBuilder.get().matchSuperEntityColumns(fieldName);
+        return superEntityColumns.stream().anyMatch(e -> e.equalsIgnoreCase(fieldName));
     }
 
-    /**
-     * @param superEntityColumns 父类字段
-     * @return this
-     * @see Entity.Builder#addSuperEntityColumns(String...)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setSuperEntityColumns(String... superEntityColumns) {
-        this.entityBuilder.get().getSuperEntityColumns().clear();    //保持语义
-        this.entityBuilder.get().getSuperEntityColumns().addAll(Arrays.asList(superEntityColumns));
+        this.superEntityColumns.addAll(Arrays.asList(superEntityColumns));
         return this;
     }
 
-    /**
-     * @param include 包含表
-     * @return this
-     * @see Builder#addInclude(String...)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setInclude(String... include) {
-        this.include.clear();   //保持语义
         this.include.addAll(Arrays.asList(include));
         return this;
     }
 
-    /**
-     * @param exclude 排除表
-     * @return this
-     * @see Builder#addExclude(String...)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setExclude(String... exclude) {
-        this.exclude.clear();   //保持语义
         this.exclude.addAll(Arrays.asList(exclude));
         return this;
     }
 
-    /**
-     * @param fieldPrefixs 字段前缀
-     * @return this
-     * @see Builder#addFieldPrefix(String...)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setFieldPrefix(String... fieldPrefixs) {
-        this.fieldPrefix.clear();   //保持语义
         this.fieldPrefix.addAll(Arrays.asList(fieldPrefixs));
         return this;
     }
@@ -385,26 +272,12 @@ public class StrategyConfig {
      *
      * @param superEntityClass 类全名称
      * @return this
-     * @see Entity.Builder#superClass(String)
-     * @deprecated 3.4.1
      */
-    @Deprecated
     public StrategyConfig setSuperEntityClass(String superEntityClass) {
-        this.entityBuilder.superClass(superEntityClass);
+        this.superEntityClass = superEntityClass;
         return this;
     }
 
-    /**
-     * 获取实体父类全名称
-     *
-     * @return 类全名称
-     * @see Entity.Builder#getSuperClass() ()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public String getSuperEntityClass() {
-        return entityBuilder.get().getSuperClass();
-    }
 
     /**
      * <p>
@@ -416,13 +289,10 @@ public class StrategyConfig {
      * </p>
      *
      * @param clazz 实体父类 Class
-     * @return this
-     * @see Entity.Builder#superClass(Class)
-     * @deprecated 3.4.1
+     * @return
      */
-    @Deprecated
     public StrategyConfig setSuperEntityClass(Class<?> clazz) {
-        this.entityBuilder.superClass(clazz);
+        this.superEntityClass = clazz.getName();
         return this;
     }
 
@@ -434,226 +304,67 @@ public class StrategyConfig {
      *
      * @param clazz        实体父类 Class
      * @param columnNaming 字段命名策略
-     * @return this
-     * @see Entity.Builder#columnNaming(NamingStrategy)
-     * @see Entity.Builder#superClass(Class)
-     * @deprecated 3.4.1 {@link #setSuperEntityClass(Class)} {@link #setColumnNaming(NamingStrategy)}
+     * @return
      */
-    @Deprecated
     public StrategyConfig setSuperEntityClass(Class<?> clazz, NamingStrategy columnNaming) {
-        this.entityBuilder.columnNaming(columnNaming);
-        this.entityBuilder.superClass(clazz);
+        this.columnNaming = columnNaming;
+        this.superEntityClass = clazz.getName();
         return this;
     }
 
-    /**
-     * Service接口父类
-     *
-     * @param clazz 类
-     * @return this
-     * @see Service.Builder#superServiceClass(Class)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setSuperServiceClass(Class<?> clazz) {
-        this.serviceBuilder.superServiceClass(clazz);
+        this.superServiceClass = clazz.getName();
         return this;
     }
 
-    /**
-     * Service接口父类
-     *
-     * @param superServiceClass 类名
-     * @return this
-     * @see Service.Builder#superServiceClass(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setSuperServiceClass(String superServiceClass) {
-        this.serviceBuilder.superServiceClass(superServiceClass);
+        this.superServiceClass = superServiceClass;
         return this;
     }
 
-    /**
-     * Service接口父类
-     *
-     * @return Service接口父类
-     * @see Service.Builder#getSuperServiceClass()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public String getSuperServiceClass() {
-        return service().getSuperServiceClass();
-    }
-
-    /**
-     * Service实现类父类
-     *
-     * @param clazz 类
-     * @return this
-     * @see Service.Builder#superServiceImplClass(Class)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setSuperServiceImplClass(Class<?> clazz) {
-        this.serviceBuilder.superServiceImplClass(clazz);
+        this.superServiceImplClass = clazz.getName();
         return this;
     }
 
-    /**
-     * Service实现类父类
-     *
-     * @param superServiceImplClass 类名
-     * @return this
-     * @see Service.Builder#superServiceImplClass(Class)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setSuperServiceImplClass(String superServiceImplClass) {
-        this.serviceBuilder.superServiceImplClass(superServiceImplClass);
+        this.superServiceImplClass = superServiceImplClass;
         return this;
     }
 
-    /**
-     * 获取Service实现类父类
-     *
-     * @return this
-     * @see Service.Builder#getSuperServiceImplClass()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public String getSuperServiceImplClass() {
-        return service().getSuperServiceImplClass();
-    }
-
-    /**
-     * 设置父类控制器
-     *
-     * @param clazz 父类控制器
-     * @return this
-     * @see Controller.Builder#superClass(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setSuperControllerClass(Class<?> clazz) {
-        this.controllerBuilder.superClass(clazz);
+        this.superControllerClass = clazz.getName();
         return this;
     }
 
-    /**
-     * 设置父类控制器
-     *
-     * @param superControllerClass 父类控制器
-     * @return this
-     * @see Controller.Builder#superClass(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public StrategyConfig setSuperControllerClass(String superControllerClass) {
-        this.controllerBuilder.superClass(superControllerClass);
-        return this;
-    }
-
-    /**
-     * 获取父类控制器
-     *
-     * @return 父类控制器
-     * @see Controller.Builder#getSuperClass()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public String getSuperControllerClass() {
-        return controller().getSuperClass();
-    }
-
-    /**
-     * 是否生成@RestController控制器
-     *
-     * @return 是否生成
-     * @see Controller.Builder#isRestStyle()
-     */
-    @Deprecated
-    public boolean isRestControllerStyle() {
-        return controller().isRestStyle();
-    }
-
-    /**
-     * 生成@RestController控制器
-     *
-     * @param restControllerStyle 是否生成
-     * @return this
-     * @see Controller.Builder#restStyle(boolean)
-     */
-    @Deprecated
-    public StrategyConfig setRestControllerStyle(boolean restControllerStyle) {
-        this.controllerBuilder.restStyle(restControllerStyle);
+        this.superControllerClass = superControllerClass;
         return this;
     }
 
-    /**
-     * 是否驼峰转连字符
-     *
-     * @return 是否驼峰转连字符
-     * @see Controller.Builder#isHyphenStyle()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public boolean isControllerMappingHyphenStyle() {
-        return controller().isHyphenStyle();
-    }
-
-    /**
-     * 是否驼峰转连字符
-     *
-     * @param controllerMappingHyphenStyle 是否驼峰转连字符
-     * @return this
-     * @see Controller.Builder#hyphenStyle(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setControllerMappingHyphenStyle(boolean controllerMappingHyphenStyle) {
-        this.controllerBuilder.hyphenStyle(controllerMappingHyphenStyle);
-        return this;
-    }
-
-    /**
-     * 设置表填充字段
-     *
-     * @param tableFillList tableFillList
-     * @see Entity.Builder#addTableFills(List)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setTableFillList(List<TableFill> tableFillList) {
-        this.entityBuilder.get().getTableFillList().clear(); //保持语义
-        this.entityBuilder.addTableFills(tableFillList.toArray(new TableFill[]{}));
-        return this;
-    }
-
-    /**
-     * 获取表填充字段
-     *
-     * @return 表填充字段
-     * @see Entity.Builder#getTableFillList()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public List<TableFill> getTableFillList() {
-        return entityBuilder.get().getTableFillList();
-    }
-
     /**
      * <p>
      * 父类 Class 反射属性转换为公共字段
      * </p>
      *
      * @param clazz 实体父类 Class
-     * @see Entity.Builder#convertSuperEntityColumns(Class)
-     * @deprecated 3.4.1
      */
-    @Deprecated
     protected void convertSuperEntityColumns(Class<?> clazz) {
-        entity().convertSuperEntityColumns(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()));
     }
 
     /**
@@ -679,466 +390,15 @@ public class StrategyConfig {
         return setChainModel(entityBuilderModel);
     }
 
-    /**
-     * @return 父类字段
-     * @see Entity.Builder#getSuperEntityColumns()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public Set<String> getSuperEntityColumns() {
-        return entity().getSuperEntityColumns();
-    }
-
-    /**
-     * 获取实体是否为链式模型
-     *
-     * @return 是否为链式模型
-     * @see Entity#isChain()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public boolean isChainModel() {
-        return entity().isChain();
-    }
-
-    /**
-     * 设置是否为链式模型
-     *
-     * @param chainModel 链式模型
-     * @return this
-     * @see Entity.Builder#chainModel(boolean)
-     * @deprecated 3.4.1
-     */
-    public StrategyConfig setChainModel(boolean chainModel) {
-        this.entityBuilder.chainModel(chainModel);
-        return this;
-    }
-
-    /**
-     * 实体是否生成serialVersionUID
-     *
-     * @return 是否生成
-     * @see Entity.Builder#isSerialVersionUID()
-     * @deprecated 3.4.1
-     */
-    public boolean isEntitySerialVersionUID() {
-        return entity().isSerialVersionUID();
-    }
-
-    /**
-     * @param entitySerialVersionUID 是否生成
-     * @return this
-     * @see Entity.Builder#serialVersionUID(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setEntitySerialVersionUID(boolean entitySerialVersionUID) {
-        this.entityBuilder.serialVersionUID(entitySerialVersionUID);
-        return this;
-    }
-
-    /**
-     * 是否为lombok模型
-     *
-     * @return 是否为lombok模型
-     * @see Entity#isLombok()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public boolean isEntityLombokModel() {
-        return entity().isLombok();
-    }
-
-    /**
-     * 设置是否为lombok模型
-     * @param entityLombokModel 是否为lombok模型
-     * @return this
-     */
-    @Deprecated
-    public StrategyConfig setEntityLombokModel(boolean entityLombokModel) {
-        this.entityBuilder.lombok(entityLombokModel);
-        return this;
-    }
-
-    /**
-     * 是否生成字段常量
-     *
-     * @return 是否生成字段常量
-     * @see Entity#isColumnConstant()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public boolean isEntityColumnConstant() {
-        return entity().isColumnConstant();
-    }
-
-    /**
-     * 是否生成字段常量
-     *
-     * @param entityColumnConstant 是否生成字段常量
-     * @return this
-     * @see Entity.Builder#columnConstant(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setEntityColumnConstant(boolean entityColumnConstant) {
-        this.entityBuilder.columnConstant(entityColumnConstant);
-        return this;
-    }
-
-    /**
-     * Boolean类型字段是否移除is前缀
-     *
-     * @return 是否移除
-     * @see Entity#isBooleanColumnRemoveIsPrefix()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public boolean isEntityBooleanColumnRemoveIsPrefix() {
-        return entity().isBooleanColumnRemoveIsPrefix();
-    }
-
-    /**
-     * Boolean类型字段是否移除is前缀
-     *
-     * @param entityBooleanColumnRemoveIsPrefix 是否移除
-     * @return this
-     * @see Entity.Builder#booleanColumnRemoveIsPrefix(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setEntityBooleanColumnRemoveIsPrefix(boolean entityBooleanColumnRemoveIsPrefix) {
-        this.entityBuilder.booleanColumnRemoveIsPrefix(entityBooleanColumnRemoveIsPrefix);
-        return this;
-    }
-
-    /**
-     * 生成实体时,是否生成字段注解
-     *
-     * @return 是否生成
-     * @see Entity.Builder#isTableFieldAnnotationEnable()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public boolean isEntityTableFieldAnnotationEnable() {
-        return entity().isTableFieldAnnotationEnable();
-    }
-
-    /**
-     * 生成实体时,是否生成字段注解
-     *
-     * @param entityTableFieldAnnotationEnable 是否生成
-     * @return this
-     * @see Entity.Builder#tableFieldAnnotationEnable(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setEntityTableFieldAnnotationEnable(boolean entityTableFieldAnnotationEnable) {
-        this.entityBuilder.tableFieldAnnotationEnable(entityTableFieldAnnotationEnable);
-        return this;
-    }
-
-    /**
-     * 乐观锁属性名称
-     *
-     * @return 乐观锁属性名称
-     * @see Entity#getVersionFieldName()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public String getVersionFieldName() {
-        return entity().getVersionFieldName();
-    }
-
-    /**
-     * 乐观锁属性名称
-     *
-     * @param versionFieldName 乐观锁属性名称
-     * @return this
-     * @see Entity.Builder#versionFieldName(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setVersionFieldName(String versionFieldName) {
-        this.entityBuilder.versionFieldName(versionFieldName);
-        return this;
-    }
-
-    /**
-     * 逻辑删除属性名称
-     *
-     * @return 逻辑删除属性名称
-     * @see Entity#getLogicDeleteFieldName()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public String getLogicDeleteFieldName() {
-        return entity().getLogicDeleteFieldName();
-    }
-
-    /**
-     * 逻辑删除属性名称
-     *
-     * @param logicDeleteFieldName 逻辑删除属性名称
-     * @return this
-     * @see Entity.Builder#logicDeleteFieldName(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setLogicDeleteFieldName(String logicDeleteFieldName) {
-        this.entityBuilder.logicDeleteFieldName(logicDeleteFieldName);
-        return this;
-    }
-
-    /**
-     * 父类Mapper
-     *
-     * @return 类名
-     * @see Mapper.Builder#getSuperClass()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public String getSuperMapperClass() {
-        return mapper().getSuperClass();
-    }
-
-    /**
-     * 父类Mapper
-     *
-     * @param superMapperClass 类名
-     * @return this
-     * @see Mapper.Builder#superClass(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setSuperMapperClass(String superMapperClass) {
-        this.mapperBuilder.superClass(superMapperClass);
-        return this;
-    }
-
-    /**
-     * 验证配置项
-     *
-     * @since 3.4.1
-     */
-    public void validate() {
-        boolean isInclude = this.getInclude().size() > 0;
-        boolean isExclude = this.getExclude().size() > 0;
-        if (isInclude && isExclude) {
-            throw new IllegalArgumentException("<strategy> 标签中 <include> 与 <exclude> 只能配置一项!");
-        }
-        if (this.getNotLikeTable() != null && this.getLikeTable() != null) {
-            throw new IllegalArgumentException("<strategy> 标签中 <likeTable> 与 <notLikeTable> 只能配置一项!");
-        }
-    }
-
-    /**
-     * 包含表名匹配
-     *
-     * @param tableName 表名
-     * @return 是否匹配
-     * @since 3.4.1
-     */
-    public boolean matchIncludeTable(String tableName) {
-        return matchTable(tableName, this.getInclude());
-    }
-
-    /**
-     * 排除表名匹配
-     *
-     * @param tableName 表名
-     * @return 是否匹配
-     * @since 3.4.1
-     */
-    public boolean matchExcludeTable(String tableName) {
-        return matchTable(tableName, this.getExclude());
-    }
-
-    /**
-     * 表名匹配
-     *
-     * @param tableName   表名
-     * @param matchTables 匹配集合
-     * @return 是否匹配
-     * @since 3.4.1
-     */
-    private boolean matchTable(String tableName, Set<String> matchTables) {
-        return matchTables.stream().anyMatch(t -> tableNameMatches(t, tableName));
-    }
-
-    /**
-     * 表名匹配
-     *
-     * @param matchTableName 匹配表名
-     * @param dbTableName    数据库表名
-     * @return 是否匹配
-     */
-    private boolean tableNameMatches(String matchTableName, String dbTableName) {
-        return matchTableName.equalsIgnoreCase(dbTableName) || StringUtils.matches(matchTableName, dbTableName);
-    }
-
-    /**
-     * 是否大写命名
-     *
-     * @param capitalMode 是否大写命名
-     * @return this
-     * @see Builder#capitalMode(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setCapitalMode(boolean capitalMode) {
-        this.isCapitalMode = capitalMode;
-        return this;
-    }
-
-    /**
-     * 是否跳过视图
-     *
-     * @param skipView 是否跳过视图
-     * @return this
-     * @see Builder#skipView(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setSkipView(boolean skipView) {
-        this.skipView = skipView;
-        return this;
-    }
-
-    /**
-     * 是否启用sql过滤
-     *
-     * @param enableSqlFilter 是否启用
-     * @return this
-     * @see Builder#enableSqlFilter(boolean)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setEnableSqlFilter(boolean enableSqlFilter) {
-        this.enableSqlFilter = enableSqlFilter;
-        return this;
-    }
-
-    /**
-     * 包含表名
-     *
-     * @param likeTable 包含表名
-     * @return this
-     * @see Builder#likeTable(LikeTable)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setLikeTable(LikeTable likeTable) {
-        this.likeTable = likeTable;
-        return this;
-    }
-
-    /**
-     * 不包含表名
-     *
-     * @param notLikeTable 不包含表名
-     * @return this
-     * @see Builder#notLikeTable(LikeTable)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public StrategyConfig setNotLikeTable(LikeTable notLikeTable) {
-        this.notLikeTable = notLikeTable;
-        return this;
-    }
-
-    /**
-     * 策略配置构建者
-     *
-     * @author nieqiurong 2020/10/11.
-     * @since 3.4.1
-     */
-    public static class Builder extends BaseBuilder {
-
-        private final StrategyConfig strategyConfig;
-
-        public Builder() {
-            super(new StrategyConfig());
-            strategyConfig = super.build();
-        }
-
-        public Builder capitalMode(boolean capitalMode){
-            this.strategyConfig.isCapitalMode = capitalMode;
-            return this;
-        }
-
-        public Builder skipView(boolean skipView){
-            this.strategyConfig.skipView = skipView;
-            return this;
-        }
-
-        public Builder enableSqlFilter(boolean enableSqlFilter){
-            this.strategyConfig.enableSqlFilter = enableSqlFilter;
-            return this;
-        }
-
-        public Builder likeTable(LikeTable likeTable){
-            this.strategyConfig.likeTable = likeTable;
-            return this;
-        }
-
-        public Builder notLikeTable(LikeTable notLikeTable) {
-            this.strategyConfig.notLikeTable = notLikeTable;
-            return this;
-        }
-
-        /**
-         * 增加字段前缀
-         *
-         * @param fieldPrefix 字段前缀
-         * @return this
-         * @since 3.4.1
-         */
-        public Builder addFieldPrefix(String... fieldPrefix) {
-            this.strategyConfig.fieldPrefix.addAll(Arrays.asList(fieldPrefix));
-            return this;
-        }
-
-        /**
-         * 增加包含的表名
-         *
-         * @param include 包含表
-         * @return this
-         * @since 3.4.1
-         */
-        public Builder addInclude(String... include) {
-            this.strategyConfig.include.addAll(Arrays.asList(include));
-            return this;
-        }
-
-        /**
-         * 增加排除表
-         *
-         * @param exclude 排除表
-         * @return this
-         * @since 3.4.1
-         */
-        public Builder addExclude(String... exclude) {
-            this.strategyConfig.exclude.addAll(Arrays.asList(exclude));
-            return this;
-        }
-
-        /**
-         * 增加表前缀
-         *
-         * @param tablePrefix 表前缀
-         * @return this
-         * @since 3.4.1
-         */
-        public Builder addTablePrefix(String... tablePrefix) {
-            this.strategyConfig.tablePrefix.addAll(Arrays.asList(tablePrefix));
-            return this;
-        }
-
-        @Override
-        public StrategyConfig build() {
-            this.strategyConfig.validate();
-            return strategyConfig;
+        if (StringUtils.isNotBlank(this.superEntityClass)) {
+            try {
+                Class<?> superEntity = ClassUtils.toClassConfident(this.superEntityClass);
+                convertSuperEntityColumns(superEntity);
+            } catch (Exception e) {
+                //当父类实体存在类加载器的时候,识别父类实体字段,不存在的情况就只有通过指定superEntityColumns属性了。
+            }
         }
+        return this.superEntityColumns;
     }
 }

+ 14 - 369
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/TemplateConfig.java

@@ -15,18 +15,10 @@
  */
 package com.baomidou.mybatisplus.generator.config;
 
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import lombok.AccessLevel;
 import lombok.Data;
 import lombok.Getter;
-import lombok.Setter;
 import lombok.experimental.Accessors;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 
 /**
  * 模板路径配置项
@@ -38,209 +30,25 @@ import java.util.regex.Pattern;
 @Accessors(chain = true)
 public class TemplateConfig {
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(TemplateConfig.class);
-
-    private static final Pattern FILE_TYPE = Pattern.compile("\\.[^.\\\\/:*?\"<>|\\r\\n]+$");
-
-    /**
-     * 由于需要支持kotlin与java两种模板,当不需要支持其中一种的话,可以使用方式一进行设置.
-     * example:
-     * 1.setEntity("/templates/entity.java") or setEntity("/templates/entity.kt")
-     * 2.setEntity("/templates/entity")
-     * 3.setEntity("/templates/entity%s")
-     * 设置实体模板路径
-     */
-    @Getter(AccessLevel.NONE)
-    private String entity;
-
     @Getter(AccessLevel.NONE)
-    @Setter(AccessLevel.NONE)
-    private boolean disableEntity;
+    private String entity = ConstVal.TEMPLATE_ENTITY_JAVA;
 
-    /**
-     * 设置实体模板路径
-     *
-     * @see #entity
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     private String entityKt = ConstVal.TEMPLATE_ENTITY_KT;
 
-    private String service;
-
-    private String serviceImpl;
-
-    private String mapper;
-
-    private String xml;
-
-    private String controller;
-
-    /**
-     * 后续不再公开此方法.
-     *
-     * @see Builder#all()
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public TemplateConfig() {
-        this.controller = ConstVal.TEMPLATE_CONTROLLER;
-        this.entity = ConstVal.TEMPLATE_ENTITY;
-        this.xml = ConstVal.TEMPLATE_XML;
-        this.service = ConstVal.TEMPLATE_SERVICE;
-        this.serviceImpl = ConstVal.TEMPLATE_SERVICE_IMPL;
-        this.mapper = ConstVal.TEMPLATE_MAPPER;
-    }
-
-    /**
-     * 设置实体模板
-     *
-     * @param entity 实体模板
-     * @return this
-     * @see Builder#entity(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public TemplateConfig setEntity(String entity) {
-        logger(entity, TemplateType.ENTITY);
-        this.entity = entity;
-        return this;
-    }
-
-    /**
-     * 设置service接口模板
-     *
-     * @param service service接口模板
-     * @return this
-     * @see Builder#service(String, String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public TemplateConfig setService(String service) {
-        logger(service, TemplateType.SERVICE);
-        this.service = service;
-        return this;
-    }
+    private String service = ConstVal.TEMPLATE_SERVICE;
 
-    /**
-     * 设置service实现类模板
-     *
-     * @param serviceImpl service实现类模板
-     * @return this
-     * @see Builder#service(String, String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public TemplateConfig setServiceImpl(String serviceImpl) {
-        logger(serviceImpl, TemplateType.SERVICE);
-        this.serviceImpl = serviceImpl;
-        return this;
-    }
+    private String serviceImpl = ConstVal.TEMPLATE_SERVICE_IMPL;
 
-    /**
-     * 设置mapper模板
-     *
-     * @param mapper mapper模板
-     * @return this
-     * @see Builder#mapper(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public TemplateConfig setMapper(String mapper) {
-        logger(mapper, TemplateType.ENTITY);
-        this.mapper = mapper;
-        return this;
-    }
+    private String mapper = ConstVal.TEMPLATE_MAPPER;
 
-    /**
-     * 设置mapperXml模板
-     *
-     * @param xml mapperXml模板
-     * @return this
-     * @see Builder#mapperXml(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public TemplateConfig setXml(String xml) {
-        logger(xml, TemplateType.XML);
-        this.xml = xml;
-        return this;
-    }
+    private String xml = ConstVal.TEMPLATE_XML;
 
-    /**
-     * 设置控制器模板
-     *
-     * @param controller 控制器模板
-     * @return this
-     * @see Builder#controller(String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public TemplateConfig setController(String controller) {
-        logger(controller, TemplateType.CONTROLLER);
-        this.controller = controller;
-        return this;
-    }
+    private String controller = ConstVal.TEMPLATE_CONTROLLER;
 
-    /**
-     * 当模板赋值为空时进行日志提示打印
-     *
-     * @param value        模板值
-     * @param templateType 模板类型
-     */
-    private void logger(String value, TemplateType templateType) {
-        if (StringUtils.isBlank(value)) {
-            LOGGER.warn("推荐使用disable(TemplateType.{})方法进行默认模板禁用.", templateType.name());
-        }
-    }
-
-    /**
-     * 设置实体模板路径
-     *
-     * @param entityKt 模板路径
-     * @deprecated 3.4.1 {@link #setEntity(String)}
-     */
-    @Deprecated
-    public TemplateConfig setEntityKt(String entityKt) {
-        return setEntity(entityKt);
-    }
-
-    /**
-     * @return 获取实体模板路径
-     * @deprecated 3.4.1 {@link #getEntity(boolean)}
-     */
-    @Deprecated
-    public String getEntityKt() {
-        return getEntity(true);
-    }
-
-    /**
-     * 获取实体模板路径
-     *
-     * @param kotlin 是否kotlin
-     * @return 模板路径
-     */
     public String getEntity(boolean kotlin) {
-        if (!disableEntity) {
-            if (StringUtils.isBlank(entity)) {
-                // 默认情况
-                return kotlin ? ConstVal.TEMPLATE_ENTITY_KT : ConstVal.TEMPLATE_ENTITY_JAVA;
-            }
-            // 用户自定义情况,尝试替换文件后缀进行加载
-            Matcher matcher = FILE_TYPE.matcher(entity);
-            if (matcher.find()) {
-                return matcher.replaceAll(kotlin ? ".kt" : ".java");
-            }
-            if (entity.endsWith("%s")) {
-                return kotlin ? String.format(entity, ".kt") : String.format(entity, ".java");
-            } else {
-                //支持无后缀情况,自动加后缀
-                return kotlin ? entity + ".kt" : entity + ".java";
-            }
-        }
-        return null;
+        return kotlin ? entityKt : entity;
     }
-
+    
     /**
      * 禁用模板
      *
@@ -253,187 +61,24 @@ public class TemplateConfig {
             for (TemplateType templateType : templateTypes) {
                 switch (templateType) {
                     case XML:
-                        this.xml = null;
+                        setXml(null);
                         break;
                     case ENTITY:
-                        this.entity = null;
-                        this.entityKt = null;
-                        //暂时没其他多的需求,使用一个单独的boolean变量进行支持一下.
-                        this.disableEntity = true;
+                        setEntity(null).setEntityKt(null);
                         break;
                     case MAPPER:
-                        this.mapper = null;
+                        setMapper(null);
                         break;
                     case SERVICE:
-                        this.service = null;
-                        this.serviceImpl = null;
+                        setService(null).setServiceImpl(null);
                         break;
                     case CONTROLLER:
-                        this.controller = null;
+                        setController(null);
                         break;
-                    default:
                 }
             }
         }
         return this;
     }
-
-    /**
-     * 禁用全部模板
-     *
-     * @return this
-     * @since 3.4.1
-     */
-    public TemplateConfig disable() {
-        return disable(TemplateType.values());
-    }
-
-
-    /**
-     * 模板路径配置构建者
-     *
-     * @author nieqiurong 3.4.1
-     */
-    public static class Builder {
-
-        private final TemplateConfig templateConfig = new TemplateConfig();
-
-        /**
-         * 默认生成一个空的
-         */
-        public Builder() {
-            // 后续去除构造之后去除此方法调用
-            templateConfig.disable(TemplateType.values());
-        }
-
-        /**
-         * 激活所有默认配置模板
-         *
-         * @return 默认配置模板
-         */
-        public Builder all() {
-            this.templateConfig.controller = ConstVal.TEMPLATE_CONTROLLER;
-            this.templateConfig.entity = ConstVal.TEMPLATE_ENTITY;
-            this.templateConfig.xml = ConstVal.TEMPLATE_XML;
-            this.templateConfig.service = ConstVal.TEMPLATE_SERVICE;
-            this.templateConfig.serviceImpl = ConstVal.TEMPLATE_SERVICE_IMPL;
-            this.templateConfig.mapper = ConstVal.TEMPLATE_MAPPER;
-            this.templateConfig.disableEntity = false;
-            return this;
-        }
-
-        /**
-         * 使用默认实体模板
-         *
-         * @return this
-         */
-        public Builder entity() {
-            return entity(ConstVal.TEMPLATE_ENTITY);
-        }
-
-        /**
-         * 设置实体模板路径
-         *
-         * @param entityTemplate 实体模板
-         * @return this
-         */
-        public Builder entity(String entityTemplate) {
-            this.templateConfig.disableEntity = false;
-            this.templateConfig.setEntity(entityTemplate);
-            return this;
-        }
-
-        /**
-         * 使用默认service模板
-         *
-         * @return this
-         */
-        public Builder service() {
-            return service(ConstVal.TEMPLATE_SERVICE, ConstVal.TEMPLATE_SERVICE_IMPL);
-        }
-
-        /**
-         * 设置service模板路径
-         *
-         * @param serviceTemplate     service接口模板路径
-         * @param serviceImplTemplate service实现类模板路径
-         * @return this
-         */
-        public Builder service(String serviceTemplate, String serviceImplTemplate) {
-            this.templateConfig.setService(serviceTemplate).setServiceImpl(serviceImplTemplate);
-            return this;
-        }
-
-        /**
-         * 使用默认mapper模板
-         *
-         * @return this
-         */
-        public Builder mapper() {
-            return mapper(ConstVal.TEMPLATE_MAPPER);
-        }
-
-        /**
-         * 设置mapper模板路径
-         *
-         * @param mapperTemplate mapper模板路径
-         * @return this
-         */
-        public Builder mapper(String mapperTemplate) {
-            this.templateConfig.setMapper(mapperTemplate);
-            return this;
-        }
-
-
-        /**
-         * 使用默认mapperXml模板
-         *
-         * @return this
-         */
-        public Builder mapperXml() {
-            return mapperXml(ConstVal.TEMPLATE_XML);
-        }
-
-        /**
-         * 设置mapperXml模板路径
-         *
-         * @param mapperXmlTemplate xml模板路径
-         * @return this
-         */
-        public Builder mapperXml(String mapperXmlTemplate) {
-            this.templateConfig.setXml(mapperXmlTemplate);
-            return this;
-        }
-
-        /**
-         * 使用默认控制器模板
-         *
-         * @return this
-         */
-        public Builder controller() {
-            return controller(ConstVal.TEMPLATE_CONTROLLER);
-        }
-
-        /**
-         * 设置控制器模板路径
-         *
-         * @param controllerTemplate 控制器模板路径
-         * @return this
-         */
-        public Builder controller(String controllerTemplate) {
-            this.templateConfig.setController(controllerTemplate);
-            return this;
-        }
-
-        /**
-         * 构建模板配置对象
-         *
-         * @return 模板配置对象
-         */
-        public TemplateConfig build() {
-            return this.templateConfig;
-        }
-
-    }
-
+    
 }

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

@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-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 Entity.Builder entityBuilder() {
-        return strategyConfig.entityBuilder();
-    }
-
-    public Controller.Builder controllerBuilder() {
-        return strategyConfig.controllerBuilder();
-    }
-
-    public Mapper.Builder mapperBuilder() {
-        return strategyConfig.mapperBuilder();
-    }
-
-    public Service.Builder serviceBuilder() {
-        return strategyConfig.serviceBuilder();
-    }
-
-    public StrategyConfig build() {
-        return this.strategyConfig;
-    }
-}

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

@@ -16,22 +16,21 @@
 package com.baomidou.mybatisplus.generator.config.builder;
 
 import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.generator.InjectionConfig;
 import com.baomidou.mybatisplus.generator.config.*;
 import com.baomidou.mybatisplus.generator.config.po.TableField;
+import com.baomidou.mybatisplus.generator.config.po.TableFill;
 import com.baomidou.mybatisplus.generator.config.po.TableInfo;
-import com.baomidou.mybatisplus.generator.config.querys.DecoratorDbQuery;
 import com.baomidou.mybatisplus.generator.config.querys.H2Query;
-import lombok.AccessLevel;
-import lombok.Data;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.experimental.Accessors;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
 
+import java.io.File;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.*;
 import java.util.regex.Pattern;
@@ -43,32 +42,32 @@ import java.util.stream.Collectors;
  * @author YangHu, tangguo, hubin, Juzi
  * @since 2016-08-30
  */
-@Data
-@Accessors(chain = true)
 public class ConfigBuilder {
 
-    private final static Logger LOGGER = LoggerFactory.getLogger(ConfigBuilder.class);
-
     /**
      * 模板路径配置信息
      */
-    @Setter(value = AccessLevel.NONE)
     private final TemplateConfig template;
     /**
      * 数据库配置
      */
-    @Getter(value = AccessLevel.NONE)
-    @Setter(value = AccessLevel.NONE)
     private final DataSourceConfig dataSourceConfig;
+    /**
+     * SQL连接
+     */
+    private final Connection connection;
     /**
      * 数据库表信息
      */
-    private final List<TableInfo> tableInfoList = new ArrayList<>();
+    private List<TableInfo> tableInfoList;
+    /**
+     * 包配置详情
+     */
+    private Map<String, String> packageInfo;
     /**
      * 路径配置信息
      */
-    @Setter(value = AccessLevel.NONE)
-    private final Map<String, String> pathInfo = new HashMap<>();
+    private Map<String, String> pathInfo;
     /**
      * 策略配置
      */
@@ -84,15 +83,7 @@ public class ConfigBuilder {
     /**
      * 过滤正则
      */
-    private static final Pattern REGX = Pattern.compile("[~!/@#$%^&*()+\\\\\\[\\]|{};:'\",<.>?]+");
-    /**
-     * 表数据查询
-     */
-    private final DecoratorDbQuery dbQuery;
-    /**
-     * 包配置信息
-     */
-    private final PackageConfig packageConfig;
+    private static final Pattern REGX = Pattern.compile("[~!/@#$%^&*()-_=+\\\\|[{}];:'\",<.>?]+");
 
     /**
      * 在构造器中处理配置
@@ -105,196 +96,592 @@ public class ConfigBuilder {
      */
     public ConfigBuilder(PackageConfig packageConfig, DataSourceConfig dataSourceConfig, StrategyConfig strategyConfig,
                          TemplateConfig template, GlobalConfig globalConfig) {
-        this.strategyConfig = Optional.ofNullable(strategyConfig).orElseGet(StrategyConfig::new);
-        //TODO 先把验证插在这里,后续改成build构建的话在build的时候验证
-        this.strategyConfig.validate();
-        this.dataSourceConfig = dataSourceConfig;
-        this.dbQuery = new DecoratorDbQuery(dataSourceConfig.getDbQuery(), dataSourceConfig, strategyConfig);
+        // 全局配置
         this.globalConfig = Optional.ofNullable(globalConfig).orElseGet(GlobalConfig::new);
-        this.template = Optional.ofNullable(template).orElseGet(() -> new TemplateConfig.Builder().all().build());
-        this.packageConfig = Optional.ofNullable(packageConfig).orElseGet(PackageConfig::new);
-        this.pathInfo.putAll(new PathInfoHandler(this.globalConfig, this.template, this.packageConfig).getPathInfo());
-        this.tableInfoList.addAll(getTablesInfo());
+        // 模板配置
+        this.template = Optional.ofNullable(template).orElseGet(TemplateConfig::new);
+        // 包配置
+        if (null == packageConfig) {
+            handlerPackage(this.template, this.globalConfig.getOutputDir(), new PackageConfig());
+        } else {
+            handlerPackage(this.template, this.globalConfig.getOutputDir(), packageConfig);
+        }
+        this.dataSourceConfig = dataSourceConfig;
+        this.connection = dataSourceConfig.getConn();
+        // 策略配置
+        this.strategyConfig = Optional.ofNullable(strategyConfig).orElseGet(StrategyConfig::new);
+        this.tableInfoList = getTablesInfo(this.strategyConfig);
     }
 
+    // ************************ 曝露方法 BEGIN*****************************
+
+    /**
+     * 所有包配置信息
+     *
+     * @return 包配置
+     */
+    public Map<String, String> getPackageInfo() {
+        return packageInfo;
+    }
+
+
+    /**
+     * 所有路径配置
+     *
+     * @return 路径配置
+     */
+    public Map<String, String> getPathInfo() {
+        return pathInfo;
+    }
+
+    /**
+     * 表信息
+     *
+     * @return 所有表信息
+     */
+    public List<TableInfo> getTableInfoList() {
+        return tableInfoList;
+    }
+
+    public ConfigBuilder setTableInfoList(List<TableInfo> tableInfoList) {
+        this.tableInfoList = tableInfoList;
+        return this;
+    }
+
+    /**
+     * 模板路径配置信息
+     *
+     * @return 所以模板路径配置信息
+     */
+    public TemplateConfig getTemplate() {
+        return this.template;
+    }
+
+    // ****************************** 曝露方法 END**********************************
+
+    /**
+     * 处理包配置
+     *
+     * @param template  TemplateConfig
+     * @param outputDir
+     * @param config    PackageConfig
+     */
+    private void handlerPackage(TemplateConfig template, String outputDir, PackageConfig config) {
+        // 包信息
+        packageInfo = CollectionUtils.newHashMapWithExpectedSize(7);
+        packageInfo.put(ConstVal.MODULE_NAME, config.getModuleName());
+        packageInfo.put(ConstVal.ENTITY, joinPackage(config.getParent(), config.getEntity()));
+        packageInfo.put(ConstVal.MAPPER, joinPackage(config.getParent(), config.getMapper()));
+        packageInfo.put(ConstVal.XML, joinPackage(config.getParent(), config.getXml()));
+        packageInfo.put(ConstVal.SERVICE, joinPackage(config.getParent(), config.getService()));
+        packageInfo.put(ConstVal.SERVICE_IMPL, joinPackage(config.getParent(), config.getServiceImpl()));
+        packageInfo.put(ConstVal.CONTROLLER, joinPackage(config.getParent(), config.getController()));
+
+        // 自定义路径
+        Map<String, String> configPathInfo = config.getPathInfo();
+        if (null != configPathInfo) {
+            pathInfo = configPathInfo;
+        } else {
+            // 生成路径信息
+            pathInfo = CollectionUtils.newHashMapWithExpectedSize(6);
+            setPathInfo(pathInfo, template.getEntity(getGlobalConfig().isKotlin()), outputDir, ConstVal.ENTITY_PATH, ConstVal.ENTITY);
+            setPathInfo(pathInfo, template.getMapper(), outputDir, ConstVal.MAPPER_PATH, ConstVal.MAPPER);
+            setPathInfo(pathInfo, template.getXml(), outputDir, ConstVal.XML_PATH, ConstVal.XML);
+            setPathInfo(pathInfo, template.getService(), outputDir, ConstVal.SERVICE_PATH, ConstVal.SERVICE);
+            setPathInfo(pathInfo, template.getServiceImpl(), outputDir, ConstVal.SERVICE_IMPL_PATH, ConstVal.SERVICE_IMPL);
+            setPathInfo(pathInfo, template.getController(), outputDir, ConstVal.CONTROLLER_PATH, ConstVal.CONTROLLER);
+        }
+    }
+
+    private void setPathInfo(Map<String, String> pathInfo, String template, String outputDir, String path, String module) {
+        if (StringUtils.isNotBlank(template)) {
+            pathInfo.put(path, joinPath(outputDir, packageInfo.get(module)));
+        }
+    }
+
+    /**
+     * 处理表对应的类名称
+     *
+     * @param tableList 表名称
+     * @param config    策略配置项
+     * @return 补充完整信息后的表
+     */
+    private List<TableInfo> processTable(List<TableInfo> tableList, StrategyConfig config) {
+        for (TableInfo tableInfo : tableList) {
+            String entityName;
+            INameConvert nameConvert = strategyConfig.getNameConvert();
+            if (null != nameConvert) {
+                // 自定义处理实体名称
+                entityName = nameConvert.entityNameConvert(tableInfo);
+            } else {
+                entityName = NamingStrategy.capitalFirst(processName(tableInfo.getName(), config.getNaming(), config.getTablePrefix()));
+            }
+            if (StringUtils.isNotBlank(globalConfig.getEntityName())) {
+                tableInfo.setConvert(true);
+                tableInfo.setEntityName(String.format(globalConfig.getEntityName(), entityName));
+            } else {
+                tableInfo.setEntityName(strategyConfig, entityName);
+            }
+            if (StringUtils.isNotBlank(globalConfig.getMapperName())) {
+                tableInfo.setMapperName(String.format(globalConfig.getMapperName(), entityName));
+            } else {
+                tableInfo.setMapperName(entityName + ConstVal.MAPPER);
+            }
+            if (StringUtils.isNotBlank(globalConfig.getXmlName())) {
+                tableInfo.setXmlName(String.format(globalConfig.getXmlName(), entityName));
+            } else {
+                tableInfo.setXmlName(entityName + ConstVal.MAPPER);
+            }
+            if (StringUtils.isNotBlank(globalConfig.getServiceName())) {
+                tableInfo.setServiceName(String.format(globalConfig.getServiceName(), entityName));
+            } else {
+                tableInfo.setServiceName("I" + entityName + ConstVal.SERVICE);
+            }
+            if (StringUtils.isNotBlank(globalConfig.getServiceImplName())) {
+                tableInfo.setServiceImplName(String.format(globalConfig.getServiceImplName(), entityName));
+            } else {
+                tableInfo.setServiceImplName(entityName + ConstVal.SERVICE_IMPL);
+            }
+            if (StringUtils.isNotBlank(globalConfig.getControllerName())) {
+                tableInfo.setControllerName(String.format(globalConfig.getControllerName(), entityName));
+            } else {
+                tableInfo.setControllerName(entityName + ConstVal.CONTROLLER);
+            }
+            // 检测导入包
+            checkImportPackages(tableInfo);
+        }
+        return tableList;
+    }
+
+    /**
+     * 检测导入包
+     *
+     * @param tableInfo ignore
+     */
+    private void checkImportPackages(TableInfo tableInfo) {
+        if (StringUtils.isNotBlank(strategyConfig.getSuperEntityClass())) {
+            // 自定义父类
+            tableInfo.getImportPackages().add(strategyConfig.getSuperEntityClass());
+        } else if (globalConfig.isActiveRecord()) {
+            // 无父类开启 AR 模式
+            tableInfo.getImportPackages().add(com.baomidou.mybatisplus.extension.activerecord.Model.class.getCanonicalName());
+        }
+        if (null != globalConfig.getIdType() && tableInfo.isHavePrimaryKey()) {
+            // 指定需要 IdType 场景
+            tableInfo.getImportPackages().add(com.baomidou.mybatisplus.annotation.IdType.class.getCanonicalName());
+            tableInfo.getImportPackages().add(com.baomidou.mybatisplus.annotation.TableId.class.getCanonicalName());
+        }
+        if (StringUtils.isNotBlank(strategyConfig.getVersionFieldName())
+            && CollectionUtils.isNotEmpty(tableInfo.getFields())) {
+            tableInfo.getFields().forEach(f -> {
+                if (strategyConfig.getVersionFieldName().equals(f.getName())) {
+                    tableInfo.getImportPackages().add(com.baomidou.mybatisplus.annotation.Version.class.getCanonicalName());
+                }
+            });
+        }
+    }
+
+
     /**
      * 获取所有的数据库表信息
      */
-    private List<TableInfo> getTablesInfo() {
-        boolean isInclude = strategyConfig.getInclude().size() > 0;
-        boolean isExclude = strategyConfig.getExclude().size() > 0;
+    private List<TableInfo> getTablesInfo(StrategyConfig config) {
+        boolean isInclude = config.getInclude().size() > 0;
+        boolean isExclude = config.getExclude().size() > 0;
+        if (isInclude && isExclude) {
+            throw new RuntimeException("<strategy> 标签中 <include> 与 <exclude> 只能配置一项!");
+        }
+        if (config.getNotLikeTable() != null && config.getLikeTable() != null) {
+            throw new RuntimeException("<strategy> 标签中 <likeTable> 与 <notLikeTable> 只能配置一项!");
+        }
         //所有的表信息
         List<TableInfo> tableList = new ArrayList<>();
 
         //需要反向生成或排除的表信息
         List<TableInfo> includeTableList = new ArrayList<>();
         List<TableInfo> excludeTableList = new ArrayList<>();
+
+        //不存在的表名
+        Set<String> notExistTables = new HashSet<>();
+        DbType dbType = this.dataSourceConfig.getDbType();
+        IDbQuery dbQuery = this.dataSourceConfig.getDbQuery();
         try {
-            dbQuery.query(dbQuery.tablesSql(), result -> {
-                String tableName = result.getStringResult(dbQuery.tableName());
-                if (StringUtils.isNotBlank(tableName)) {
-                    TableInfo tableInfo = new TableInfo();
+            String tablesSql = dataSourceConfig.getDbQuery().tablesSql();
+            if (DbType.POSTGRE_SQL == dbType) {
+                String schema = dataSourceConfig.getSchemaName();
+                if (schema == null) {
+                    //pg 默认 schema=public
+                    schema = "public";
+                    dataSourceConfig.setSchemaName(schema);
+                }
+                tablesSql = String.format(tablesSql, schema);
+            } else if (DbType.KINGBASE_ES == dbType) {
+                String schema = dataSourceConfig.getSchemaName();
+                if (schema == null) {
+                    //kingbase 默认 schema=PUBLIC
+                    schema = "PUBLIC";
+                    dataSourceConfig.setSchemaName(schema);
+                }
+                tablesSql = String.format(tablesSql, schema);
+            } else if (DbType.DB2 == dbType) {
+                String schema = dataSourceConfig.getSchemaName();
+                if (schema == null) {
+                    //db2 默认 schema=current schema
+                    schema = "current schema";
+                    dataSourceConfig.setSchemaName(schema);
+                }
+                tablesSql = String.format(tablesSql, schema);
+            }
+            //oracle数据库表太多,出现最大游标错误
+            else if (DbType.ORACLE == dbType) {
+                String schema = dataSourceConfig.getSchemaName();
+                //oracle 默认 schema=username
+                if (schema == null) {
+                    schema = dataSourceConfig.getUsername().toUpperCase();
+                    dataSourceConfig.setSchemaName(schema);
+                }
+                tablesSql = String.format(tablesSql, schema);
+            }
+            StringBuilder sql = new StringBuilder(tablesSql);
+            if (config.isEnableSqlFilter()) {
+                if (config.getLikeTable() != null) {
+                    sql.append(" AND ").append(dbQuery.tableName()).append(" LIKE '").append(config.getLikeTable().getValue()).append("'");
+                } else if (config.getNotLikeTable() != null) {
+                    sql.append(" AND ").append(dbQuery.tableName()).append(" NOT LIKE '").append(config.getNotLikeTable().getValue()).append("'");
+                }
+                if (isInclude) {
+                    sql.append(" AND ").append(dbQuery.tableName()).append(" IN (")
+                        .append(config.getInclude().stream().map(tb -> "'" + tb + "'").collect(Collectors.joining(","))).append(")");
+                } else if (isExclude) {
+                    sql.append(" AND ").append(dbQuery.tableName()).append(" NOT IN (")
+                        .append(config.getExclude().stream().map(tb -> "'" + tb + "'").collect(Collectors.joining(","))).append(")");
+                }
+            }
+            TableInfo tableInfo;
+            try (PreparedStatement preparedStatement = connection.prepareStatement(sql.toString());
+                 ResultSet results = preparedStatement.executeQuery()) {
+                while (results.next()) {
+                    final String tableName = results.getString(dbQuery.tableName());
+                    if (StringUtils.isBlank(tableName)) {
+                        System.err.println("当前数据库为空!!!");
+                        continue;
+                    }
+                    tableInfo = new TableInfo();
                     tableInfo.setName(tableName);
-                    String tableComment = result.getTableComment();
-                    // 跳过视图
-                    if (!(strategyConfig.isSkipView() && "VIEW".equals(tableComment))) {
-                        tableInfo.setComment(tableComment);
-                        if (isInclude && strategyConfig.matchIncludeTable(tableName)) {
-                            includeTableList.add(tableInfo);
-                        } else if (isExclude && strategyConfig.matchExcludeTable(tableName)) {
-                            excludeTableList.add(tableInfo);
+                    String commentColumn = dbQuery.tableComment();
+                    if (StringUtils.isNotBlank(commentColumn)) {
+                        String tableComment = results.getString(commentColumn);
+                        if (config.isSkipView() && "VIEW".equals(tableComment)) {
+                            // 跳过视图
+                            continue;
                         }
-                        tableList.add(tableInfo);
+                        tableInfo.setComment(formatComment(tableComment));
                     }
-                }
-            });
-            //TODO 我要把这个打印不存在表的功能和正则匹配功能删掉,就算是苗老板来了也拦不住的那种
-            if (isExclude || isInclude) {
-                Map<String, String> notExistTables = new HashSet<>(isExclude ? strategyConfig.getExclude() : strategyConfig.getInclude())
-                    .stream()
-                    .filter(s -> !matcherRegTable(s))
-                    .collect(Collectors.toMap(String::toLowerCase, s -> s, (o, n) -> n));
-                // 将已经存在的表移除,获取配置中数据库不存在的表
-                for (TableInfo tabInfo : tableList) {
-                    if (notExistTables.isEmpty()) {
-                        break;
+
+                    if (isInclude) {
+                        for (String includeTable : config.getInclude()) {
+                            // 忽略大小写等于 或 正则 true
+                            if (tableNameMatches(includeTable, tableName)) {
+                                includeTableList.add(tableInfo);
+                            } else {
+                                //过滤正则表名
+                                if (!REGX.matcher(includeTable).find()) {
+                                    notExistTables.add(includeTable);
+                                }
+                            }
+                        }
+                    } else if (isExclude) {
+                        for (String excludeTable : config.getExclude()) {
+                            // 忽略大小写等于 或 正则 true
+                            if (tableNameMatches(excludeTable, tableName)) {
+                                excludeTableList.add(tableInfo);
+                            } else {
+                                //过滤正则表名
+                                if (!REGX.matcher(excludeTable).find()) {
+                                    notExistTables.add(excludeTable);
+                                }
+                            }
+                        }
                     }
-                    //解决可能大小写不敏感的情况导致无法移除掉
-                    notExistTables.remove(tabInfo.getName().toLowerCase());
-                }
-                if (notExistTables.size() > 0) {
-                    LOGGER.warn("表[{}]在数据库中不存在!!!", String.join(StringPool.COMMA, notExistTables.values()));
-                }
-                // 需要反向生成的表信息
-                if (isExclude) {
-                    tableList.removeAll(excludeTableList);
-                } else {
-                    tableList.clear();
-                    tableList.addAll(includeTableList);
+                    tableList.add(tableInfo);
                 }
             }
+            // 将已经存在的表移除,获取配置中数据库不存在的表
+            for (TableInfo tabInfo : tableList) {
+                notExistTables.remove(tabInfo.getName());
+            }
+            if (notExistTables.size() > 0) {
+                System.err.println("表 " + notExistTables + " 在数据库中不存在!!!");
+            }
+
+            // 需要反向生成的表信息
+            if (isExclude) {
+                tableList.removeAll(excludeTableList);
+                includeTableList = tableList;
+            }
+            if (!isInclude && !isExclude) {
+                includeTableList = tableList;
+            }
             // 性能优化,只处理需执行表字段 github issues/219
-            tableList.forEach(this::convertTableFields);
-            // 数据库操作完成,释放连接对象
-            dbQuery.closeConnection();
+            includeTableList.forEach(ti -> convertTableFields(ti, config));
         } catch (SQLException e) {
-            throw new RuntimeException(e);
+            e.printStackTrace();
         }
-        return tableList;
+        return processTable(includeTableList, config);
+    }
+
+
+    /**
+     * 表名匹配
+     *
+     * @param setTableName 设置表名
+     * @param dbTableName  数据库表单
+     * @return ignore
+     */
+    private boolean tableNameMatches(String setTableName, String dbTableName) {
+        return setTableName.equalsIgnoreCase(dbTableName)
+            || StringUtils.matches(setTableName, dbTableName);
     }
 
     /**
      * 将字段信息与表信息关联
      *
      * @param tableInfo 表信息
+     * @param config    命名策略
+     * @return ignore
      */
-    private void convertTableFields(TableInfo tableInfo) {
+    private TableInfo convertTableFields(TableInfo tableInfo, StrategyConfig config) {
+        boolean haveId = false;
         List<TableField> fieldList = new ArrayList<>();
         List<TableField> commonFieldList = new ArrayList<>();
         DbType dbType = this.dataSourceConfig.getDbType();
+        IDbQuery dbQuery = dataSourceConfig.getDbQuery();
         String tableName = tableInfo.getName();
         try {
-            String tableFieldsSql = dbQuery.tableFieldsSql(tableName);
+            String tableFieldsSql = dbQuery.tableFieldsSql();
             Set<String> h2PkColumns = new HashSet<>();
-            if (DbType.H2 == dbType) {
-                dbQuery.query(String.format(H2Query.PK_QUERY_SQL, tableName), result -> {
-                    String primaryKey = result.getStringResult(dbQuery.fieldKey());
-                    if (Boolean.parseBoolean(primaryKey)) {
-                        h2PkColumns.add(result.getStringResult(dbQuery.fieldName()));
+            if (DbType.POSTGRE_SQL == dbType) {
+                //TODO 还原代码后解决PgSchema的问题.
+                this.connection.setSchema(dataSourceConfig.getSchemaName());
+                tableFieldsSql = String.format(tableFieldsSql, dataSourceConfig.getSchemaName(), tableName);
+            } else if (DbType.KINGBASE_ES == dbType) {
+                tableFieldsSql = String.format(tableFieldsSql, dataSourceConfig.getSchemaName(), tableName);
+            } else if (DbType.DB2 == dbType) {
+                tableFieldsSql = String.format(tableFieldsSql, dataSourceConfig.getSchemaName(), tableName);
+            } else if (DbType.ORACLE == dbType) {
+                tableName = tableName.toUpperCase();
+                tableFieldsSql = String.format(tableFieldsSql.replace("#schema", dataSourceConfig.getSchemaName()), tableName);
+            } else if (DbType.DM == dbType) {
+                tableName = tableName.toUpperCase();
+                tableFieldsSql = String.format(tableFieldsSql, tableName);
+            } else if (DbType.H2 == dbType) {
+                try (PreparedStatement pkQueryStmt = connection.prepareStatement(String.format(H2Query.PK_QUERY_SQL, tableName));
+                     ResultSet pkResults = pkQueryStmt.executeQuery()) {
+                    while (pkResults.next()) {
+                        String primaryKey = pkResults.getString(dbQuery.fieldKey());
+                        if (Boolean.parseBoolean(primaryKey)) {
+                            h2PkColumns.add(pkResults.getString(dbQuery.fieldName()));
+                        }
                     }
-                });
-            }
-            dbQuery.query(tableFieldsSql, result -> {
-                TableField field = new TableField();
-                String columnName = result.getStringResult(dbQuery.fieldName());
-                // 避免多重主键设置,目前只取第一个找到ID,并放到list中的索引为0的位置
-                boolean isId = DbType.H2 == dbType ? h2PkColumns.contains(columnName) : result.isPrimaryKey();
-                // 处理ID
-                if (isId) {
-                    field.setKeyFlag(true).setKeyIdentityFlag(dbQuery.isKeyIdentity(result.getResultSet()));
-                    tableInfo.setHavePrimaryKey(true);
-                }
-                String newColumnName = columnName;
-                IKeyWordsHandler keyWordsHandler = dataSourceConfig.getKeyWordsHandler();
-                if (keyWordsHandler != null && keyWordsHandler.isKeyWords(columnName)) {
-                    LOGGER.warn("当前表[{}]存在字段[{}]为数据库关键字或保留字!", tableName, columnName);
-                    field.setKeyWords(true);
-                    newColumnName = keyWordsHandler.formatColumn(columnName);
                 }
-                field.setName(columnName).setColumnName(newColumnName)
-                    .setType(result.getStringResult(dbQuery.fieldType()))
-                    .setPropertyName(strategyConfig.entity().getNameConvert().propertyNameConvert(field), this.strategyConfig, dataSourceConfig.getTypeConvert().processTypeConvert(globalConfig, field))
-                    .setComment(result.getFiledComment())
-                    .setCustomMap(dbQuery.getCustomFields(result.getResultSet()));
-                // 填充逻辑判断
-                strategyConfig.entity().getTableFillList().stream()
-                    //忽略大写字段问题
-                    .filter(tf -> tf.getFieldName().equalsIgnoreCase(field.getName()))
-                    .findFirst().ifPresent(tf -> field.setFill(tf.getFieldFill().name()));
-                if (strategyConfig.entity().matchSuperEntityColumns(field.getName())) {
-                    // 跳过公共字段
-                    commonFieldList.add(field);
-                } else {
+                tableFieldsSql = String.format(tableFieldsSql, tableName);
+            } else {
+                tableFieldsSql = String.format(tableFieldsSql, tableName);
+            }
+            try (
+                PreparedStatement preparedStatement = connection.prepareStatement(tableFieldsSql);
+                ResultSet results = preparedStatement.executeQuery()) {
+                while (results.next()) {
+                    TableField field = new TableField();
+                    String columnName = results.getString(dbQuery.fieldName());
+                    // 避免多重主键设置,目前只取第一个找到ID,并放到list中的索引为0的位置
+                    boolean isId;
+                    if (DbType.H2 == dbType) {
+                        isId = h2PkColumns.contains(columnName);
+                    } else {
+                        String key = results.getString(dbQuery.fieldKey());
+                        if (DbType.DB2 == dbType || DbType.SQLITE == dbType) {
+                            isId = StringUtils.isNotBlank(key) && "1".equals(key);
+                        } else {
+                            isId = StringUtils.isNotBlank(key) && "PRI".equals(key.toUpperCase());
+                        }
+                    }
+
+                    // 处理ID
+                    if (isId && !haveId) {
+                        haveId = true;
+                        field.setKeyFlag(true);
+                        tableInfo.setHavePrimaryKey(true);
+                        field.setKeyIdentityFlag(dbQuery.isKeyIdentity(results));
+                    } else {
+                        field.setKeyFlag(false);
+                    }
+                    // 自定义字段查询
+                    String[] fcs = dbQuery.fieldCustom();
+                    if (null != fcs) {
+                        Map<String, Object> customMap = CollectionUtils.newHashMapWithExpectedSize(fcs.length);
+                        for (String fc : fcs) {
+                            customMap.put(fc, results.getObject(fc));
+                        }
+                        field.setCustomMap(customMap);
+                    }
+                    // 处理其它信息
+                    field.setName(columnName);
+                    String newColumnName = columnName;
+                    IKeyWordsHandler keyWordsHandler = dataSourceConfig.getKeyWordsHandler();
+                    if (keyWordsHandler != null && keyWordsHandler.isKeyWords(columnName)) {
+                        System.err.printf("当前表[%s]存在字段[%s]为数据库关键字或保留字!%n", tableName, columnName);
+                        field.setKeyWords(true);
+                        newColumnName = keyWordsHandler.formatColumn(columnName);
+                    }
+                    field.setColumnName(newColumnName);
+                    field.setType(results.getString(dbQuery.fieldType()));
+                    INameConvert nameConvert = strategyConfig.getNameConvert();
+                    if (null != nameConvert) {
+                        field.setPropertyName(nameConvert.propertyNameConvert(field));
+                    } else {
+                        field.setPropertyName(strategyConfig, processName(field.getName(), config.getColumnNaming()));
+                    }
+                    field.setColumnType(dataSourceConfig.getTypeConvert().processTypeConvert(globalConfig, field));
+                    String fieldCommentColumn = dbQuery.fieldComment();
+                    if (StringUtils.isNotBlank(fieldCommentColumn)) {
+                        field.setComment(formatComment(results.getString(fieldCommentColumn)));
+                    }
+                    // 填充逻辑判断
+                    List<TableFill> tableFillList = getStrategyConfig().getTableFillList();
+                    if (null != tableFillList) {
+                        // 忽略大写字段问题
+                        tableFillList.stream().filter(tf -> tf.getFieldName().equalsIgnoreCase(field.getName()))
+                            .findFirst().ifPresent(tf -> field.setFill(tf.getFieldFill().name()));
+                    }
+                    if (strategyConfig.includeSuperEntityColumns(field.getName())) {
+                        // 跳过公共字段
+                        commonFieldList.add(field);
+                        continue;
+                    }
                     fieldList.add(field);
                 }
-            });
+            }
         } catch (SQLException e) {
-            throw new RuntimeException(e);
+            System.err.println("SQL Exception:" + e.getMessage());
         }
-        tableInfo.addFields(fieldList);
-        tableInfo.addCommonFields(commonFieldList);
-        tableInfo.processTable(strategyConfig, globalConfig);
+        tableInfo.setFields(fieldList);
+        tableInfo.setCommonFields(commonFieldList);
+        return tableInfo;
     }
 
+
     /**
-     * 格式化数据库注释内容
+     * 连接路径字符串
      *
-     * @param comment 注释
-     * @return 注释
-     * @see DecoratorDbQuery.ResultSetWrapper#formatComment(java.lang.String)
-     * @since 3.4.0
-     * @deprecated 3.4.1
+     * @param parentDir   路径常量字符串
+     * @param packageName 包名
+     * @return 连接后的路径
      */
-    @Deprecated
-    public String formatComment(String comment) {
-        return StringUtils.isBlank(comment) ? StringPool.EMPTY : comment.replaceAll("\r\n", "\t");
+    private String joinPath(String parentDir, String packageName) {
+        if (StringUtils.isBlank(parentDir)) {
+            parentDir = System.getProperty(ConstVal.JAVA_TMPDIR);
+        }
+        if (!StringUtils.endsWith(parentDir, File.separator)) {
+            parentDir += File.separator;
+        }
+        packageName = packageName.replaceAll("\\.", StringPool.BACK_SLASH + File.separator);
+        return parentDir + packageName;
     }
 
+
     /**
-     * 不再建议调用此方法,后续不再公开此方法.
+     * 连接父子包名
      *
-     * @param tableInfoList tableInfoList
-     * @return configBuild
-     * @deprecated 3.4.1 {@link #getTableInfoList()} 返回引用,如果有需要请直接操作
+     * @param parent     父包名
+     * @param subPackage 子包名
+     * @return 连接后的包名
      */
-    @Deprecated
-    public ConfigBuilder setTableInfoList(List<TableInfo> tableInfoList) {
-        this.tableInfoList.clear(); //保持语义
-        this.tableInfoList.addAll(tableInfoList);
-        return this;
+    private String joinPackage(String parent, String subPackage) {
+        return StringUtils.isBlank(parent) ? subPackage : (parent + StringPool.DOT + subPackage);
     }
 
+
     /**
-     * 判断表名是否为正则表名(这表名规范比较随意,只能尽量匹配上特殊符号)
+     * 处理字段名称
      *
-     * @param tableName 表名
-     * @return 是否正则
-     * @since 3.4.1
+     * @return 根据策略返回处理后的名称
      */
-    public static boolean matcherRegTable(String tableName) {
-        return REGX.matcher(tableName).find();
+    private String processName(String name, NamingStrategy strategy) {
+        return processName(name, strategy, strategyConfig.getFieldPrefix());
     }
 
+
     /**
-     * 获取包配置信息
+     * 处理表/字段名称
      *
-     * @return 包配置信息
-     * @see PackageConfig#getPackageInfo()
-     * @deprecated 3.4.1
+     * @param name     ignore
+     * @param strategy ignore
+     * @param prefix   ignore
+     * @return 根据策略返回处理后的名称
      */
-    @Deprecated
-    public Map<String, String> getPackageInfo() {
-        return packageConfig.getPackageInfo();
+    private String processName(String name, NamingStrategy strategy, Set<String> prefix) {
+        String propertyName;
+        if (prefix.size() > 0) {
+            if (strategy == NamingStrategy.underline_to_camel) {
+                // 删除前缀、下划线转驼峰
+                propertyName = NamingStrategy.removePrefixAndCamel(name, prefix);
+            } else {
+                // 删除前缀
+                propertyName = NamingStrategy.removePrefix(name, prefix);
+            }
+        } else if (strategy == NamingStrategy.underline_to_camel) {
+            // 下划线转驼峰
+            propertyName = NamingStrategy.underlineToCamel(name);
+        } else {
+            // 不处理
+            propertyName = name;
+        }
+        return propertyName;
+    }
+
+
+    public StrategyConfig getStrategyConfig() {
+        return strategyConfig;
+    }
+
+
+    public ConfigBuilder setStrategyConfig(StrategyConfig strategyConfig) {
+        this.strategyConfig = strategyConfig;
+        return this;
+    }
+
+
+    public GlobalConfig getGlobalConfig() {
+        return globalConfig;
+    }
+
+
+    public ConfigBuilder setGlobalConfig(GlobalConfig globalConfig) {
+        this.globalConfig = globalConfig;
+        return this;
+    }
+
+
+    public InjectionConfig getInjectionConfig() {
+        return injectionConfig;
+    }
+
+
+    public ConfigBuilder setInjectionConfig(InjectionConfig injectionConfig) {
+        this.injectionConfig = injectionConfig;
+        return this;
+    }
+
+    /**
+     * 格式化数据库注释内容
+     *
+     * @param comment 注释
+     * @return 注释
+     * @since 3.4.0
+     */
+    public String formatComment(String comment) {
+        return StringUtils.isBlank(comment) ? StringPool.EMPTY : comment.replaceAll("\r\n", "\t");
     }
 
 }

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

@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-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 - 394
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/Entity.java

@@ -1,394 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.generator.config.builder;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-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 Entity {
-
-    private Entity() {
-
-    }
-
-    /**
-     * 名称转换
-     */
-    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;
-
-    /**
-     * 开启 ActiveRecord 模式
-     *
-     * @since 3.4.1
-     */
-    private boolean activeRecord;
-
-    /**
-     * 指定生成的主键的ID类型
-     *
-     * @since 3.4.1
-     */
-    private IdType idType;
-
-    /**
-     * <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));
-    }
-
-    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;
-        }
-
-        /**
-         * 开启 ActiveRecord 模式
-         *
-         * @param activeRecord 是否开启
-         * @return this
-         * @since 3.4.1
-         */
-        public Builder activeRecord(boolean activeRecord) {
-            this.entity.activeRecord = activeRecord;
-            return this;
-        }
-
-        /**
-         * 指定生成的主键的ID类型
-         *
-         * @param idType ID类型
-         * @return this
-         * @since 3.4.1
-         */
-        public Builder idType(IdType idType) {
-            this.entity.idType = idType;
-            return this;
-        }
-
-        public Entity get(){
-            return this.entity;
-        }
-    }
-}

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

@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-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;
-
-    /**
-     * 开启 BaseResultMap
-     *
-     * @since 3.4.1
-     */
-    private boolean baseResultMap;
-
-    /**
-     * 开启 baseColumnList
-     *
-     * @since 3.4.1
-     */
-    private boolean baseColumnList;
-
-    /**
-     * 是否在xml中添加二级缓存配置
-     *
-     * @since 3.4.1
-     */
-    private boolean enableXmlCache;
-
-    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());
-        }
-
-        /**
-         * 开启baseResultMap
-         *
-         * @param baseResultMap 是否开启baseResultMap
-         * @return this
-         * @since 3.4.1
-         */
-        public Builder baseResultMap(boolean baseResultMap){
-            this.mapper.baseResultMap = baseResultMap;
-            return this;
-        }
-
-        /**
-         * 开启baseColumnList
-         *
-         * @param baseColumnList 是否开启baseColumnList
-         * @return this
-         * @since 3.4.1
-         */
-        public Builder baseColumnList(boolean baseColumnList) {
-            this.mapper.baseColumnList = baseColumnList;
-            return this;
-        }
-
-        /**
-         * 是否在xml中添加二级缓存配置
-         *
-         * @param enableXmlCache 是否开启
-         * @return this
-         */
-        public Builder enableXmlCache(boolean enableXmlCache) {
-            this.mapper.enableXmlCache = enableXmlCache;
-            return this;
-        }
-
-        public Mapper get() {
-            return this.mapper;
-        }
-    }
-}

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

@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.generator.config.builder;
-
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-import com.baomidou.mybatisplus.generator.config.ConstVal;
-import com.baomidou.mybatisplus.generator.config.GlobalConfig;
-import com.baomidou.mybatisplus.generator.config.PackageConfig;
-import com.baomidou.mybatisplus.generator.config.TemplateConfig;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * 路径信息处理
- *
- * @author nieqiurong 2020/10/6.
- * @since 3.4.1
- */
-class PathInfoHandler {
-
-    private final Map<String, String> pathInfo = new HashMap<>();
-
-    private final String outputDir;
-
-    private final PackageConfig packageConfig;
-
-    PathInfoHandler(GlobalConfig globalConfig, TemplateConfig templateConfig, PackageConfig packageConfig) {
-        this.outputDir = globalConfig.getOutputDir();
-        this.packageConfig = packageConfig;
-        Map<String, String> pathInfo = packageConfig.getPathInfo();
-        if (CollectionUtils.isNotEmpty(pathInfo)) {
-            this.pathInfo.putAll(pathInfo);
-        } else {
-            putPathInfo(templateConfig.getEntity(globalConfig.isKotlin()), ConstVal.ENTITY_PATH, ConstVal.ENTITY);
-            putPathInfo(templateConfig.getMapper(), ConstVal.MAPPER_PATH, ConstVal.MAPPER);
-            putPathInfo(templateConfig.getXml(), ConstVal.XML_PATH, ConstVal.XML);
-            putPathInfo(templateConfig.getService(), ConstVal.SERVICE_PATH, ConstVal.SERVICE);
-            putPathInfo(templateConfig.getServiceImpl(), ConstVal.SERVICE_IMPL_PATH, ConstVal.SERVICE_IMPL);
-            putPathInfo(templateConfig.getController(), ConstVal.CONTROLLER_PATH, ConstVal.CONTROLLER);
-        }
-    }
-
-    public Map<String, String> getPathInfo() {
-        return Collections.unmodifiableMap(this.pathInfo);
-    }
-
-    private void putPathInfo(String template, String path, String module) {
-        if (StringUtils.isNotBlank(template)) pathInfo.put(path, joinPath(outputDir, packageConfig.getPackageInfo(module)));
-    }
-
-    /**
-     * 连接路径字符串
-     *
-     * @param parentDir   路径常量字符串
-     * @param packageName 包名
-     * @return 连接后的路径
-     */
-    private String joinPath(String parentDir, String packageName) {
-        if (StringUtils.isBlank(parentDir)) {
-            parentDir = System.getProperty(ConstVal.JAVA_TMPDIR);
-        }
-        if (!StringUtils.endsWith(parentDir, File.separator)) {
-            parentDir += File.separator;
-        }
-        packageName = packageName.replaceAll("\\.", StringPool.BACK_SLASH + File.separator);
-        return parentDir + packageName;
-    }
-}

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

@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-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;
-        }
-    }
-}

+ 1 - 1
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/po/LikeTable.java

@@ -27,7 +27,7 @@ import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
  */
 public class LikeTable {
 
-    private final String value;
+    private String value;
 
     private SqlLike like = SqlLike.DEFAULT;
 

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

@@ -62,27 +62,21 @@ public class TableField {
      */
     private Map<String, Object> customMap;
 
-    /**
-     * @param convert
-     * @return this
-     * @see #setConvert(StrategyConfig)
-     * @deprecated 3.4.1
-     */
     public TableField setConvert(boolean convert) {
         this.convert = convert;
         return this;
     }
 
     protected TableField setConvert(StrategyConfig strategyConfig) {
-        if (strategyConfig.entity().isTableFieldAnnotationEnable() || isKeyWords()) {
+        if (strategyConfig.isEntityTableFieldAnnotationEnable() || isKeyWords()) {
             this.convert = true;
             return this;
         }
         if (strategyConfig.isCapitalModeNaming(name)) {
-            this.convert = !name.equalsIgnoreCase(propertyName);
+            this.convert = false;
         } else {
             // 转换字段
-            if (NamingStrategy.underline_to_camel == strategyConfig.entity().getColumnNaming()) {
+            if (NamingStrategy.underline_to_camel == strategyConfig.getColumnNaming()) {
                 // 包含大写处理
                 if (StringUtils.containsUpperCase(name)) {
                     this.convert = true;
@@ -94,64 +88,12 @@ public class TableField {
         return this;
     }
 
-
-    /**
-     * @param propertyName 属性名称
-     * @return this
-     * @deprecated 3.4.1 {@link #setPropertyName(String, StrategyConfig, IColumnType)}
-     */
-    @Deprecated
-    public TableField setPropertyName(String propertyName) {
-        this.propertyName = propertyName;
-        return this;
-    }
-
-    /**
-     * 设置属性名称
-     *
-     * @param propertyName   属性名
-     * @param strategyConfig 策略配置
-     * @param columnType     字段类型
-     * @return this
-     * @since 3.4.1
-     */
-    public TableField setPropertyName(String propertyName, StrategyConfig strategyConfig, IColumnType columnType) {
-        this.columnType = columnType;
-        if (strategyConfig.entity().isBooleanColumnRemoveIsPrefix()
-            && "boolean".equalsIgnoreCase(this.getPropertyType()) && propertyName.startsWith("is")) {
-            this.convert = true;
-            this.propertyName = StringUtils.removePrefixAfterPrefixToLower(propertyName, 2);
-            return this;
-        }
+    public TableField setPropertyName(StrategyConfig strategyConfig, String propertyName) {
         this.propertyName = propertyName;
         this.setConvert(strategyConfig);
         return this;
     }
 
-    /**
-     * 设置属性名称
-     *
-     * @param strategyConfig 策略配置
-     * @param propertyName   属性名
-     * @return this
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public TableField setPropertyName(StrategyConfig strategyConfig, String propertyName) {
-        return setPropertyName(propertyName, strategyConfig, this.columnType);
-    }
-
-    /**
-     * @param columnType 字段类型
-     * @return this
-     * @deprecated 3.4.1 {@link #setPropertyName(String, StrategyConfig, IColumnType)}
-     */
-    @Deprecated
-    public TableField setColumnType(IColumnType columnType) {
-        this.columnType = columnType;
-        return this;
-    }
-
     public String getPropertyType() {
         if (null != columnType) {
             return columnType.getType();
@@ -192,4 +134,5 @@ public class TableField {
         }
         return columnName;
     }
+
 }

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

@@ -15,26 +15,13 @@
  */
 package com.baomidou.mybatisplus.generator.config.po;
 
-import java.io.Serializable;
-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.function.Supplier;
-import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-import com.baomidou.mybatisplus.extension.activerecord.Model;
-import com.baomidou.mybatisplus.generator.config.ConstVal;
-import com.baomidou.mybatisplus.generator.config.GlobalConfig;
 import com.baomidou.mybatisplus.generator.config.StrategyConfig;
 import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
 
@@ -61,36 +48,29 @@ public class TableInfo {
     private String serviceName;
     private String serviceImplName;
     private String controllerName;
-    private final List<TableField> fields = new ArrayList<>();
+    private List<TableField> fields;
     private boolean havePrimaryKey;
     /**
      * 公共字段
      */
-    private final List<TableField> commonFields = new ArrayList<>();
+    private List<TableField> commonFields;
     private String fieldNames;
 
-    /**
-     * @param convert convert
-     * @return this
-     * @see #setConvert(StrategyConfig)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public TableInfo setConvert(boolean convert) {
         this.convert = convert;
         return this;
     }
 
     protected TableInfo setConvert(StrategyConfig strategyConfig) {
-        if (strategyConfig.startsWithTablePrefix(name) || strategyConfig.entity().isTableFieldAnnotationEnable()) {
+        if (strategyConfig.startsWithTablePrefix(name) || strategyConfig.isEntityTableFieldAnnotationEnable()) {
             // 包含前缀
             this.convert = true;
         } else if (strategyConfig.isCapitalModeNaming(name)) {
             // 包含
-            this.convert = !entityName.equalsIgnoreCase(name);
+            this.convert = false;
         } else {
             // 转换字段
-            if (NamingStrategy.underline_to_camel == strategyConfig.entity().getColumnNaming()) {
+            if (NamingStrategy.underline_to_camel == strategyConfig.getColumnNaming()) {
                 // 包含大写处理
                 if (StringUtils.containsUpperCase(name)) {
                     this.convert = true;
@@ -106,76 +86,50 @@ public class TableInfo {
         return entityName.substring(0, 1).toLowerCase() + entityName.substring(1);
     }
 
-    /**
-     * @param entityName 实体名称
-     * @return this
-     * @see #setEntityName(StrategyConfig, String)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public TableInfo setEntityName(String entityName) {
-        this.entityName = entityName;
-        return this;
-    }
-
     public TableInfo setEntityName(StrategyConfig strategyConfig, String entityName) {
         this.entityName = entityName;
         this.setConvert(strategyConfig);
         return this;
     }
 
-
-    /**
-     * @see #addFields(List)
-     * @see #addFields(TableField...)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public TableInfo setFields(List<TableField> fields) {
-        this.fields.clear();    //保持语义
-        return addFields(fields);
-    }
-
-    /**
-     * @param fields 字段集合
-     * @return this
-     * @since 3.4.1
-     */
-    public TableInfo addFields(List<TableField> fields) {
-        this.fields.addAll(fields);
-        return this;
-    }
-
-    /**
-     * @param fields 字段集合
-     * @return this
-     * @since 3.4.1
-     */
-    public TableInfo addFields(TableField... fields) {
-        this.fields.addAll(Arrays.asList(fields));
+        this.fields = fields;
+        if (CollectionUtils.isNotEmpty(fields)) {
+            // 收集导入包信息
+            for (TableField field : fields) {
+                if (null != field.getColumnType() && null != field.getColumnType().getPkg()) {
+                    importPackages.add(field.getColumnType().getPkg());
+                }
+                if (field.isKeyFlag()) {
+                    // 主键
+                    if (field.isConvert() || field.isKeyIdentityFlag()) {
+                        importPackages.add(com.baomidou.mybatisplus.annotation.TableId.class.getCanonicalName());
+                    }
+                    // 自增
+                    if (field.isKeyIdentityFlag()) {
+                        importPackages.add(com.baomidou.mybatisplus.annotation.IdType.class.getCanonicalName());
+                    }
+                } else if (field.isConvert()) {
+                    // 普通字段
+                    importPackages.add(com.baomidou.mybatisplus.annotation.TableField.class.getCanonicalName());
+                }
+                if (null != field.getFill()) {
+                    // 填充字段
+                    importPackages.add(com.baomidou.mybatisplus.annotation.TableField.class.getCanonicalName());
+                    importPackages.add(com.baomidou.mybatisplus.annotation.FieldFill.class.getCanonicalName());
+                }
+            }
+        }
         return this;
     }
 
-    /**
-     * @param pkg 包空间
-     * @return this
-     * @see #addImportPackages(String...)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
     public TableInfo setImportPackages(String pkg) {
-        importPackages.clear(); //保持语义
-        return addImportPackages(pkg);
-    }
-
-    /**
-     * @param pkgs 包空间
-     * @return this
-     * @since 3.4.1
-     */
-    public TableInfo addImportPackages(String... pkgs) {
-        importPackages.addAll(Arrays.asList(pkgs));
-        return this;
+        if (importPackages.contains(pkg)) {
+            return this;
+        } else {
+            importPackages.add(pkg);
+            return this;
+        }
     }
 
     /**
@@ -185,157 +139,24 @@ public class TableInfo {
         return fields.parallelStream().anyMatch(tf -> tf.getName().equals(logicDeletePropertyName));
     }
 
-    /**
-     * @param fieldNames fieldNames
-     * @deprecated 3.4.1 不打算公开此方法了
-     */
-    @Deprecated
-    public TableInfo setFieldNames(String fieldNames) {
-        this.fieldNames = fieldNames;
-        return this;
-    }
-
     /**
      * 转换filed实体为 xml mapper 中的 base column 字符串信息
      */
     public String getFieldNames() {
-        //TODO 感觉这个也啥必要,不打算公开set方法了
-        if (StringUtils.isBlank(fieldNames)) {
-            this.fieldNames = this.fields.stream().map(TableField::getColumnName).collect(Collectors.joining(", "));
-        }
-        return this.fieldNames;
-    }
-
-    /**
-     * @param commonFields 公共字段
-     * @return this
-     * @see #addCommonFields(TableField...)
-     * @see #addCommonFields(List)
-     * @deprecated 3.4.1
-     */
-    @Deprecated
-    public TableInfo setCommonFields(List<TableField> commonFields) {
-        this.commonFields.clear(); //保持语义
-        return addCommonFields(commonFields);
-    }
-
-    /**
-     * 添加公共字段
-     *
-     * @param commonFields 公共字段
-     * @return this
-     * @since 3.4.1
-     */
-    public TableInfo addCommonFields(TableField... commonFields) {
-        return addCommonFields(Arrays.asList(commonFields));
-    }
-
-    /**
-     * 添加公共字段
-     *
-     * @param commonFields 公共字段
-     * @return this
-     * @since 3.4.1
-     */
-    public TableInfo addCommonFields(List<TableField> commonFields) {
-        this.commonFields.addAll(commonFields);
-        return this;
-    }
-
-    /**
-     * 导包处理
-     *
-     * @param strategyConfig 策略配置
-     * @param globalConfig   全局配置
-     * @since 3.4.1
-     */
-    public void importPackage(StrategyConfig strategyConfig, GlobalConfig globalConfig) {
-        boolean importSerializable = true;
-        if (StringUtils.isNotBlank(strategyConfig.entity().getSuperClass())) {
-            // 自定义父类
-            importSerializable = false;
-            this.importPackages.add(strategyConfig.entity().getSuperClass());
-        } else {
-            if (globalConfig.isActiveRecord() || strategyConfig.entity().isActiveRecord()) {
-                // 无父类开启 AR 模式
-                this.importPackages.add(Model.class.getCanonicalName());
-                importSerializable = false;
-            }
-        }
-        if (importSerializable) {
-            this.importPackages.add(Serializable.class.getCanonicalName());
-        }
-        if (this.isConvert()) {
-            this.importPackages.add(TableName.class.getCanonicalName());
-        }
-        if (strategyConfig.entity().getLogicDeleteFieldName() != null && this.isLogicDelete(strategyConfig.entity().getLogicDeleteFieldName())) {
-            this.importPackages.add(TableLogic.class.getCanonicalName());
-        }
-        IdType idType = Optional.ofNullable(strategyConfig.entity().getIdType()).orElseGet(globalConfig::getIdType);
-        if (null != idType && this.isHavePrimaryKey()) {
-            // 指定需要 IdType 场景
-            this.importPackages.add(IdType.class.getCanonicalName());
-            this.importPackages.add(TableId.class.getCanonicalName());
-        }
-        this.fields.forEach(field -> {
-            if (null != field.getColumnType() && null != field.getColumnType().getPkg()) {
-                importPackages.add(field.getColumnType().getPkg());
-            }
-            if (field.isKeyFlag()) {
-                // 主键
-                if (field.isConvert() || field.isKeyIdentityFlag()) {
-                    importPackages.add(TableId.class.getCanonicalName());
-                }
-                // 自增
-                if (field.isKeyIdentityFlag()) {
-                    importPackages.add(IdType.class.getCanonicalName());
+        if (StringUtils.isBlank(fieldNames)
+            && CollectionUtils.isNotEmpty(fields)) {
+            StringBuilder names = new StringBuilder();
+            IntStream.range(0, fields.size()).forEach(i -> {
+                TableField fd = fields.get(i);
+                if (i == fields.size() - 1) {
+                    names.append(fd.getColumnName());
+                } else {
+                    names.append(fd.getColumnName()).append(", ");
                 }
-            } else if (field.isConvert()) {
-                // 普通字段
-                importPackages.add(com.baomidou.mybatisplus.annotation.TableField.class.getCanonicalName());
-            }
-            if (null != field.getFill()) {
-                // 填充字段
-                importPackages.add(com.baomidou.mybatisplus.annotation.TableField.class.getCanonicalName());
-                //TODO 好像default的不用处理也行,这个做优化项目.
-                importPackages.add(FieldFill.class.getCanonicalName());
-            }
-            String versionFieldName = strategyConfig.entity().getVersionFieldName();
-            if (StringUtils.isNotBlank(versionFieldName) && versionFieldName.equals(field.getName())) {
-                this.importPackages.add(Version.class.getCanonicalName());
-            }
-        });
-    }
-
-    /**
-     * 处理表信息(文件名与导包)
-     *
-     * @param strategyConfig 策略配置
-     * @param globalConfig   全局配置
-     * @since 3.4.1
-     */
-    public void processTable(StrategyConfig strategyConfig, GlobalConfig globalConfig) {
-        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);
-        this.serviceName = this.getFileName(entityName, globalConfig.getServiceName(), () -> "I" + entityName + ConstVal.SERVICE);
-        this.serviceImplName = this.getFileName(entityName, globalConfig.getServiceImplName(), () -> entityName + ConstVal.SERVICE_IMPL);
-        this.controllerName = this.getFileName(entityName, globalConfig.getControllerName(), () -> entityName + ConstVal.CONTROLLER);
-        this.importPackage(strategyConfig, globalConfig);
+            });
+            fieldNames = names.toString();
+        }
+        return fieldNames;
     }
 
-
-    /**
-     * 获取文件名称(含格式化处理)
-     *
-     * @param entityName   实体名
-     * @param value        文件名(支持格式化处理)
-     * @param defaultValue 默认文件名
-     * @return 文件名称
-     * @since 3.4.1
-     */
-    public String getFileName(String entityName, String value, Supplier<String> defaultValue) {
-        return StringUtils.isNotBlank(value) ? String.format(value, entityName) : defaultValue.get();
-    }
 }

+ 0 - 259
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/querys/DecoratorDbQuery.java

@@ -1,259 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.generator.config.querys;
-
-import com.baomidou.mybatisplus.annotation.DbType;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
-import com.baomidou.mybatisplus.generator.config.IDbQuery;
-import com.baomidou.mybatisplus.generator.config.StrategyConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
-import java.util.function.Consumer;
-import java.util.stream.Collectors;
-
-/**
- * 装饰DbQuery
- *
- * @author nieqiurong 2020/9/17.
- * @since 3.4.1
- */
-public class DecoratorDbQuery extends AbstractDbQuery {
-
-    private final IDbQuery dbQuery;
-    private final Connection connection;
-    private final DbType dbType;
-    private final StrategyConfig strategyConfig;
-    private final String schema;
-    private final Logger logger;
-
-    public DecoratorDbQuery(IDbQuery dbQuery, DataSourceConfig dataSourceConfig, StrategyConfig strategyConfig) {
-        this.dbQuery = dbQuery;
-        this.connection = dataSourceConfig.getConn();
-        this.dbType = dataSourceConfig.getDbType();
-        this.strategyConfig = strategyConfig;
-        this.schema = dataSourceConfig.getSchemaName();
-        this.logger = LoggerFactory.getLogger(dbQuery.getClass());
-    }
-
-    @Override
-    public String tablesSql() {
-        String tablesSql = dbQuery.tablesSql();
-        if (DbType.POSTGRE_SQL == dbType || DbType.KINGBASE_ES == dbType || DbType.DB2 == dbType || DbType.ORACLE == dbType) {
-            tablesSql = String.format(tablesSql, this.schema);
-        }
-        if (strategyConfig.isEnableSqlFilter()) {
-            StringBuilder sql = new StringBuilder(tablesSql);
-            boolean isInclude = strategyConfig.getInclude().size() > 0;
-            boolean isExclude = strategyConfig.getExclude().size() > 0;
-            if (strategyConfig.getLikeTable() != null) {
-                sql.append(" AND ").append(dbQuery.tableName()).append(" LIKE '").append(strategyConfig.getLikeTable().getValue()).append("'");
-            } else if (strategyConfig.getNotLikeTable() != null) {
-                sql.append(" AND ").append(dbQuery.tableName()).append(" NOT LIKE '").append(strategyConfig.getNotLikeTable().getValue()).append("'");
-            }
-            if (isInclude) {
-                sql.append(" AND ").append(dbQuery.tableName()).append(" IN (")
-                    .append(strategyConfig.getInclude().stream().map(tb -> "'" + tb + "'").collect(Collectors.joining(","))).append(")");
-            } else if (isExclude) {
-                sql.append(" AND ").append(dbQuery.tableName()).append(" NOT IN (")
-                    .append(strategyConfig.getExclude().stream().map(tb -> "'" + tb + "'").collect(Collectors.joining(","))).append(")");
-            }
-            return sql.toString();
-        }
-        return tablesSql;
-    }
-
-    @Override
-    public String tableFieldsSql() {
-        return dbQuery.tableFieldsSql();
-    }
-
-    /**
-     * 扩展{@link #tableFieldsSql()}方法
-     *
-     * @param tableName 表名
-     * @return 查询表字段语句
-     */
-    public String tableFieldsSql(String tableName) {
-        String tableFieldsSql = this.tableFieldsSql();
-        if (DbType.KINGBASE_ES == dbType || DbType.DB2 == dbType) {
-            tableFieldsSql = String.format(tableFieldsSql, this.schema, tableName);
-        } else if (DbType.ORACLE == dbType) {
-            tableName = tableName.toUpperCase();
-            tableFieldsSql = String.format(tableFieldsSql.replace("#schema", this.schema), tableName);
-        } else if (DbType.DM == dbType) {
-            tableName = tableName.toUpperCase();
-            tableFieldsSql = String.format(tableFieldsSql, tableName);
-        } else {
-            tableFieldsSql = String.format(tableFieldsSql, tableName);
-        }
-        return tableFieldsSql;
-    }
-
-    @Override
-    public String tableName() {
-        return dbQuery.tableName();
-    }
-
-    @Override
-    public String tableComment() {
-        return dbQuery.tableComment();
-    }
-
-    @Override
-    public String fieldName() {
-        return dbQuery.fieldName();
-    }
-
-    @Override
-    public String fieldType() {
-        return dbQuery.fieldType();
-    }
-
-    @Override
-    public String fieldComment() {
-        return dbQuery.fieldComment();
-    }
-
-    @Override
-    public String fieldKey() {
-        return dbQuery.fieldKey();
-    }
-
-    @Override
-    public boolean isKeyIdentity(ResultSet results) {
-        try {
-            return dbQuery.isKeyIdentity(results);
-        } catch (SQLException e) {
-            logger.warn("判断主键自增错误:{}", e.getMessage());
-            // ignore 这个看到在查H2的时候出了异常,先忽略这个异常了.
-        }
-        return false;
-    }
-
-    @Override
-    public String[] fieldCustom() {
-        return dbQuery.fieldCustom();
-    }
-
-    public Map<String, Object> getCustomFields(ResultSet resultSet) {
-        String[] fcs = this.fieldCustom();
-        if (null != fcs) {
-            Map<String, Object> customMap = CollectionUtils.newHashMapWithExpectedSize(fcs.length);
-            for (String fc : fcs) {
-                try {
-                    customMap.put(fc, resultSet.getObject(fc));
-                } catch (SQLException sqlException) {
-                    throw new RuntimeException("获取自定义字段错误:", sqlException);
-                }
-            }
-            return customMap;
-        }
-        return Collections.emptyMap();
-    }
-
-    public void query(String sql, Consumer<ResultSetWrapper> consumer) throws SQLException {
-        logger.debug("执行SQL:{}", sql);
-        int count = 0;
-        long start = System.nanoTime();
-        try (PreparedStatement preparedStatement = connection.prepareStatement(sql);
-             ResultSet resultSet = preparedStatement.executeQuery()) {
-            while (resultSet.next()) {
-                consumer.accept(new ResultSetWrapper(resultSet, this, this.dbType));
-                count++;
-            }
-            long end = System.nanoTime();
-            logger.debug("返回记录数:{},耗时(ms):{}", count, (end - start) / 1000000);
-        }
-    }
-
-    public Connection getConnection() {
-        return connection;
-    }
-
-    public void closeConnection() {
-        Optional.ofNullable(connection).ifPresent((con) -> {
-            try {
-                con.close();
-            } catch (SQLException sqlException) {
-                sqlException.printStackTrace();
-            }
-        });
-    }
-
-    public static class ResultSetWrapper {
-
-        private final IDbQuery dbQuery;
-
-        private final ResultSet resultSet;
-
-        private final DbType dbType;
-
-        ResultSetWrapper(ResultSet resultSet, IDbQuery dbQuery, DbType dbType) {
-            this.resultSet = resultSet;
-            this.dbQuery = dbQuery;
-            this.dbType = dbType;
-        }
-
-        public ResultSet getResultSet() {
-            return resultSet;
-        }
-
-        public String getStringResult(String columnLabel) {
-            try {
-                return resultSet.getString(columnLabel);
-            } catch (SQLException sqlException) {
-                throw new RuntimeException(String.format("读取[%s]字段出错!", columnLabel), sqlException);
-            }
-        }
-
-        public String getFiledComment() {
-            return getComment(dbQuery.fieldComment());
-
-        }
-
-        private String getComment(String columnLabel) {
-            return StringUtils.isNotBlank(columnLabel) ? formatComment(getStringResult(columnLabel)) : StringPool.EMPTY;
-        }
-
-        public String getTableComment() {
-            return getComment(dbQuery.tableComment());
-        }
-
-        public String formatComment(String comment) {
-            return StringUtils.isBlank(comment) ? StringPool.EMPTY : comment.replaceAll("\r\n", "\t");
-        }
-
-        public boolean isPrimaryKey() {
-            String key = this.getStringResult(dbQuery.fieldKey());
-            if (DbType.DB2 == dbType || DbType.SQLITE == dbType) {
-                return StringUtils.isNotBlank(key) && "1".equals(key);
-            } else {
-                return StringUtils.isNotBlank(key) && "PRI".equals(key.toUpperCase());
-            }
-        }
-    }
-}

+ 8 - 6
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/rules/NamingStrategy.java

@@ -86,10 +86,14 @@ public enum NamingStrategy {
         if (StringUtils.isBlank(name)) {
             return StringPool.EMPTY;
         }
-        // 判断是否有匹配的前缀,然后截取前缀
-        // 删除前缀 TODO 前缀统一配置小写格式????
-        return prefix.stream().filter(pf -> name.toLowerCase().startsWith(pf))
-            .findFirst().map(pf -> name.substring(pf.length())).orElse(name);
+        if (null != prefix) {
+            // 判断是否有匹配的前缀,然后截取前缀
+            // 删除前缀
+            return prefix.stream().filter(pf -> name.toLowerCase()
+                .matches(StringPool.HAT + pf.toLowerCase() + ".*"))
+                .findFirst().map(pf -> name.substring(pf.length())).orElse(name);
+        }
+        return name;
     }
 
     /**
@@ -98,9 +102,7 @@ public enum NamingStrategy {
      * @param name   ignore
      * @param prefix ignore
      * @return ignore
-     * @deprecated 3.4.1
      */
-    @Deprecated
     public static boolean isPrefixContained(String name, String... prefix) {
         if (null == prefix || StringUtils.isBlank(name)) {
             return false;

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

@@ -15,7 +15,6 @@
  */
 package com.baomidou.mybatisplus.generator.engine;
 
-import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@@ -44,8 +43,7 @@ import java.util.*;
  */
 public abstract class AbstractTemplateEngine {
 
-    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
-
+    protected static final Logger logger = LoggerFactory.getLogger(AbstractTemplateEngine.class);
     /**
      * 配置信息
      */
@@ -67,12 +65,12 @@ public abstract class AbstractTemplateEngine {
     public AbstractTemplateEngine batchOutput() {
         try {
             List<TableInfo> tableInfoList = getConfigBuilder().getTableInfoList();
-            Map<String, String> pathInfo = getConfigBuilder().getPathInfo();
-            TemplateConfig template = getConfigBuilder().getTemplate();
-            // 自定义内容
-            InjectionConfig injectionConfig = getConfigBuilder().getInjectionConfig();
             for (TableInfo tableInfo : tableInfoList) {
                 Map<String, Object> objectMap = getObjectMap(tableInfo);
+                Map<String, String> pathInfo = getConfigBuilder().getPathInfo();
+                TemplateConfig template = getConfigBuilder().getTemplate();
+                // 自定义内容
+                InjectionConfig injectionConfig = getConfigBuilder().getInjectionConfig();
                 if (null != injectionConfig) {
                     injectionConfig.initTableMap(tableInfo);
                     objectMap.put("cfg", injectionConfig.getMap());
@@ -199,46 +197,45 @@ public abstract class AbstractTemplateEngine {
     public Map<String, Object> getObjectMap(TableInfo tableInfo) {
         Map<String, Object> objectMap;
         ConfigBuilder config = getConfigBuilder();
-        if (config.getStrategyConfig().controller().isHyphenStyle()) {
+        if (config.getStrategyConfig().isControllerMappingHyphenStyle()) {
             objectMap = CollectionUtils.newHashMapWithExpectedSize(33);
-            objectMap.put("controllerMappingHyphenStyle", config.getStrategyConfig().controller().isHyphenStyle());
+            objectMap.put("controllerMappingHyphenStyle", config.getStrategyConfig().isControllerMappingHyphenStyle());
             objectMap.put("controllerMappingHyphen", StringUtils.camelToHyphen(tableInfo.getEntityPath()));
         } else {
             objectMap = CollectionUtils.newHashMapWithExpectedSize(31);
         }
-        objectMap.put("restControllerStyle", config.getStrategyConfig().controller().isRestStyle());
+        objectMap.put("restControllerStyle", config.getStrategyConfig().isRestControllerStyle());
         objectMap.put("config", config);
-        objectMap.put("package", config.getPackageConfig().getPackageInfo());
+        objectMap.put("package", config.getPackageInfo());
         GlobalConfig globalConfig = config.getGlobalConfig();
         objectMap.put("author", globalConfig.getAuthor());
-        IdType idType = Optional.ofNullable(config.getStrategyConfig().entity().getIdType()).orElseGet(globalConfig::getIdType);
-        objectMap.put("idType", idType == null ? null : idType.toString());
-        objectMap.put("logicDeleteFieldName", config.getStrategyConfig().entity().getLogicDeleteFieldName());
-        objectMap.put("versionFieldName", config.getStrategyConfig().entity().getVersionFieldName());
-        objectMap.put("activeRecord", globalConfig.isActiveRecord() || config.getStrategyConfig().entity().isActiveRecord());
+        objectMap.put("idType", globalConfig.getIdType() == null ? null : globalConfig.getIdType().toString());
+        objectMap.put("logicDeleteFieldName", config.getStrategyConfig().getLogicDeleteFieldName());
+        objectMap.put("versionFieldName", config.getStrategyConfig().getVersionFieldName());
+        objectMap.put("activeRecord", globalConfig.isActiveRecord());
         objectMap.put("kotlin", globalConfig.isKotlin());
         objectMap.put("swagger2", globalConfig.isSwagger2());
         objectMap.put("date", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
         objectMap.put("table", tableInfo);
-        objectMap.put("enableCache", globalConfig.isEnableCache() || config.getStrategyConfig().mapper().isEnableXmlCache());
-        objectMap.put("baseResultMap", globalConfig.isBaseResultMap() || config.getStrategyConfig().mapper().isBaseResultMap());
-        objectMap.put("baseColumnList", globalConfig.isBaseColumnList() || config.getStrategyConfig().mapper().isBaseResultMap());
+        objectMap.put("enableCache", globalConfig.isEnableCache());
+        objectMap.put("baseResultMap", globalConfig.isBaseResultMap());
+        objectMap.put("baseColumnList", globalConfig.isBaseColumnList());
         objectMap.put("entity", tableInfo.getEntityName());
-        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()));
+        objectMap.put("entitySerialVersionUID", config.getStrategyConfig().isEntitySerialVersionUID());
+        objectMap.put("entityColumnConstant", config.getStrategyConfig().isEntityColumnConstant());
+        objectMap.put("entityBuilderModel", config.getStrategyConfig().isEntityBuilderModel());
+        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()));
         return Objects.isNull(config.getInjectionConfig()) ? objectMap : config.getInjectionConfig().prepareObjectMap(objectMap);
     }
 

+ 1 - 2
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/engine/BeetlTemplateEngine.java

@@ -58,8 +58,7 @@ public class BeetlTemplateEngine extends AbstractTemplateEngine {
             Configuration cfg = Configuration.defaultConfiguration();
             groupTemplate = new GroupTemplate(new ClasspathResourceLoader("/"), cfg);
         } catch (IOException e) {
-            logger.error("初始化模板引擎失败:", e);
-            throw new RuntimeException(e);
+            logger.error(e.getMessage(), e);
         }
         return this;
     }

+ 4 - 5
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/keywords/BaseKeyWordsHandler.java

@@ -27,19 +27,18 @@ import java.util.Locale;
  * @since 3.3.2
  */
 public abstract class BaseKeyWordsHandler implements IKeyWordsHandler {
-
+    
     public List<String> keyWords;
-
+    
     public BaseKeyWordsHandler(List<String> keyWords) {
         this.keyWords = keyWords;
     }
-
+    
     @Override
     public List<String> getKeyWords() {
         return keyWords;
     }
-
-    @Override
+    
     public boolean isKeyWords(String columnName) {
         return getKeyWords().contains(columnName.toUpperCase(Locale.ENGLISH));
     }

+ 6 - 6
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/keywords/H2KeyWordsHandler.java

@@ -27,8 +27,8 @@ import java.util.List;
  * @since 3.3.2
  */
 public class H2KeyWordsHandler extends BaseKeyWordsHandler {
-
-    private static final List<String> KEY_WORDS = new ArrayList<>(Arrays.asList(
+    
+    private static List<String> KEY_WORDS = new ArrayList<>(Arrays.asList(
         "ALL",
         "AND",
         "ARRAY",
@@ -110,18 +110,18 @@ public class H2KeyWordsHandler extends BaseKeyWordsHandler {
         "WINDOW",
         "WITH"
     ));
-
+    
     public H2KeyWordsHandler() {
         super(KEY_WORDS);
     }
-
+    
     public H2KeyWordsHandler(List<String> keyWords) {
         super(keyWords);
     }
-
+    
     @Override
     public String formatStyle() {
         return "\"%s\"";
     }
-
+    
 }

+ 6 - 6
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/keywords/MySqlKeyWordsHandler.java

@@ -27,8 +27,8 @@ import java.util.List;
  * @since 3.3.2
  */
 public class MySqlKeyWordsHandler extends BaseKeyWordsHandler {
-
-    private static final List<String> KEY_WORDS = new ArrayList<>(Arrays.asList(
+    
+    private static List<String> KEY_WORDS = new ArrayList<>(Arrays.asList(
         "ACCESSIBLE",
         "ACCOUNT",
         "ACTION",
@@ -651,18 +651,18 @@ public class MySqlKeyWordsHandler extends BaseKeyWordsHandler {
         "YEAR",
         "YEAR_MONTH",
         "ZEROFILL"));
-
+    
     public MySqlKeyWordsHandler() {
         super(KEY_WORDS);
     }
-
+    
     public MySqlKeyWordsHandler(List<String> keyWords) {
         super(keyWords);
     }
-
+    
     @Override
     public String formatStyle() {
         return "`%s`";
     }
-
+    
 }

+ 6 - 6
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/keywords/PostgreSqlKeyWordsHandler.java

@@ -27,8 +27,8 @@ import java.util.List;
  * @since 3.3.2
  */
 public class PostgreSqlKeyWordsHandler extends BaseKeyWordsHandler {
-
-    private static final List<String> KEY_WORDS = new ArrayList<>(Arrays.asList(
+    
+    private static List<String> KEY_WORDS = new ArrayList<>(Arrays.asList(
         "ALL",
         "ANALYSE",
         "ANALYZE",
@@ -130,18 +130,18 @@ public class PostgreSqlKeyWordsHandler extends BaseKeyWordsHandler {
         "WINDOW",
         "WITH"
     ));
-
+    
     public PostgreSqlKeyWordsHandler() {
         super(KEY_WORDS);
     }
-
+    
     public PostgreSqlKeyWordsHandler(List<String> keyWords) {
         super(keyWords);
     }
-
+    
     @Override
     public String formatStyle() {
         return "\"%s\"";
     }
-
+    
 }

+ 0 - 48
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/DataSourceConfigTest.java

@@ -1,48 +0,0 @@
-package com.baomidou.mybatisplus.generator.config;
-
-import com.baomidou.mybatisplus.annotation.DbType;
-import com.baomidou.mybatisplus.generator.config.converts.PostgreSqlTypeConvert;
-import com.baomidou.mybatisplus.generator.config.querys.H2Query;
-import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
-import com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler;
-import org.h2.Driver;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-
-/**
- *
- * @author nieqiurong 2020/10/10.
- */
-public class DataSourceConfigTest {
-
-    @Test
-    void buildTest() {
-        DataSourceConfig dataSourceConfig;
-        dataSourceConfig = new DataSourceConfig.Builder("jdbc:h2:mem:test;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE", "sa", "").build();
-        Assertions.assertNotNull(dataSourceConfig.getDbType());
-        Assertions.assertNotNull(dataSourceConfig.getConn());
-        Assertions.assertNotNull(dataSourceConfig.getTypeConvert());
-        Assertions.assertEquals(dataSourceConfig.getDbType(), DbType.H2);
-        Assertions.assertEquals(dataSourceConfig.getDbQuery().getClass(), H2Query.class);
-
-        dataSourceConfig = new DataSourceConfig.Builder("jdbc:h2:mem:test;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE", "sa", "").driver(Driver.class).build();
-        Assertions.assertNotNull(dataSourceConfig.getDbType());
-        Assertions.assertNotNull(dataSourceConfig.getConn());
-        Assertions.assertNotNull(dataSourceConfig.getTypeConvert());
-        Assertions.assertEquals(Driver.class.getName(), dataSourceConfig.getDriverName());
-        Assertions.assertEquals(dataSourceConfig.getDbType(), DbType.H2);
-        Assertions.assertEquals(dataSourceConfig.getDbQuery().getClass(), H2Query.class);
-
-        dataSourceConfig = new DataSourceConfig.Builder("jdbc:h2:mem:test;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE", "sa", "")
-            .dbType(DbType.MYSQL).dbQuery(new MySqlQuery()).schema("mp").keyWordsHandler(new MySqlKeyWordsHandler()).typeConvert(new PostgreSqlTypeConvert())
-            .driver(Driver.class).build();
-        Assertions.assertEquals(dataSourceConfig.getSchemaName(), "mp");
-        Assertions.assertEquals(dataSourceConfig.getDriverName(), Driver.class.getName());
-        Assertions.assertEquals(dataSourceConfig.getDbType(), DbType.MYSQL);
-        Assertions.assertEquals(dataSourceConfig.getDbQuery().getClass(), MySqlQuery.class);
-        Assertions.assertEquals(dataSourceConfig.getKeyWordsHandler().getClass(), MySqlKeyWordsHandler.class);
-        Assertions.assertEquals(dataSourceConfig.getTypeConvert().getClass(), PostgreSqlTypeConvert.class);
-    }
-
-}

+ 0 - 33
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/GlobalConfigTest.java

@@ -1,33 +0,0 @@
-package com.baomidou.mybatisplus.generator.config;
-
-import com.baomidou.mybatisplus.generator.config.rules.DateType;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- * @author nieqiurong 2020/10/12.
- */
-public class GlobalConfigTest {
-
-    private void buildAssert(GlobalConfig globalConfig) {
-        Assertions.assertTrue(globalConfig.isKotlin());
-        Assertions.assertTrue(globalConfig.isSwagger2());
-        Assertions.assertTrue(globalConfig.isOpen());
-        Assertions.assertEquals(globalConfig.getAuthor(), "mp");
-        Assertions.assertEquals(globalConfig.getOutputDir(), "/temp/code");
-        Assertions.assertEquals(globalConfig.getDateType(), DateType.SQL_PACK);
-    }
-
-    @Test
-    void builderTest() {
-        GlobalConfig globalConfig;
-        globalConfig = new GlobalConfig().setAuthor("mp")
-            .setDateType(DateType.SQL_PACK).setOpen(true).setOutputDir("/temp/code")
-            .setActiveRecord(true).setBaseColumnList(true).setBaseResultMap(true).setKotlin(true).setSwagger2(true);
-        buildAssert(globalConfig);
-        globalConfig = new GlobalConfig.Builder().author("mp")
-            .dateType(DateType.SQL_PACK).openDir(true).outputDir("/temp/code").activeRecord(true).baseColumnList(true)
-            .baseColumnList(true).kotlin(true).swagger2(true).build();
-        buildAssert(globalConfig);
-    }
-}

+ 0 - 41
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/PackageConfigTest.java

@@ -1,41 +0,0 @@
-package com.baomidou.mybatisplus.generator.config;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-
-/**
- * @author nieqiurong 2020/10/6.
- */
-public class PackageConfigTest {
-
-    @Test
-    void joinPackageTest() {
-        Assertions.assertEquals("com.baomidou.demo", new PackageConfig().joinPackage("demo"));
-        Assertions.assertEquals("com.baomidou.mp.demo", new PackageConfig().setModuleName("mp").joinPackage("demo"));
-        Assertions.assertEquals("com.baomihua.demo", new PackageConfig().setParent("com.baomihua").joinPackage("demo"));
-        Assertions.assertEquals("com.baomihua.mp.demo", new PackageConfig().setParent("com.baomihua").setModuleName("mp").joinPackage("demo"));
-    }
-
-    private void buildAssert(PackageConfig packageConfig){
-        Assertions.assertEquals(packageConfig.getParent(),"com.baomihua.demo");
-        Assertions.assertEquals(packageConfig.getModuleName(),"demo");
-        Assertions.assertEquals(packageConfig.getController(),"action");
-        Assertions.assertEquals(packageConfig.getEntity(),"entity");
-        Assertions.assertEquals(packageConfig.getMapper(),"dao");
-        Assertions.assertEquals(packageConfig.getService(),"iservice");
-        Assertions.assertEquals(packageConfig.getServiceImpl(),"serviceIm");
-        Assertions.assertEquals(1,packageConfig.getPathInfo().size());
-        Assertions.assertTrue(packageConfig.getPathInfo().containsKey("aaaa"));
-    }
-
-    @Test
-    void buildTest(){
-        buildAssert(new PackageConfig().setParent("com.baomihua")
-            .setModuleName("demo").setController("action").setEntity("entity").setMapper("dao").setService("iservice").setServiceImpl("serviceIm").setPathInfo(Collections.singletonMap("aaaa","bbbb")));
-        buildAssert(new PackageConfig.Builder().parent("com.baomihua")
-            .moduleName("demo").controller("action").entity("entity").mapper("dao").service("iservice").serviceImpl("serviceIm").pathInfo(Collections.singletonMap("aaaa","bbbb")).build());
-    }
-
-}

+ 0 - 107
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/TemplateConfigTest.java

@@ -1,107 +0,0 @@
-package com.baomidou.mybatisplus.generator.config;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- *
- * @author nieqiurong 2020/10/10.
- */
-public class TemplateConfigTest {
-
-    @Test
-    void disableTest() {
-        TemplateConfig templateConfig;
-        templateConfig = new TemplateConfig().disable();
-        Assertions.assertNull(templateConfig.getController());
-        Assertions.assertNull(templateConfig.getService());
-        Assertions.assertNull(templateConfig.getServiceImpl());
-        Assertions.assertNull(templateConfig.getMapper());
-        Assertions.assertNull(templateConfig.getXml());
-        Assertions.assertNull(templateConfig.getEntity(true));
-        Assertions.assertNull(templateConfig.getEntity(false));
-
-        templateConfig = new TemplateConfig.Builder().build();
-        Assertions.assertNull(templateConfig.getController());
-        Assertions.assertNull(templateConfig.getService());
-        Assertions.assertNull(templateConfig.getServiceImpl());
-        Assertions.assertNull(templateConfig.getMapper());
-        Assertions.assertNull(templateConfig.getXml());
-        Assertions.assertNull(templateConfig.getEntity(true));
-        Assertions.assertNull(templateConfig.getEntity(false));
-
-
-        templateConfig = new TemplateConfig().disable(TemplateType.SERVICE);
-        Assertions.assertNull(templateConfig.getServiceImpl());
-        Assertions.assertNull(templateConfig.getService());
-        Assertions.assertNotNull(templateConfig.getEntity(true));
-        Assertions.assertNotNull(templateConfig.getEntity(false));
-
-        templateConfig = new TemplateConfig.Builder().all().build().disable(TemplateType.SERVICE);
-        Assertions.assertNull(templateConfig.getServiceImpl());
-        Assertions.assertNull(templateConfig.getService());
-        Assertions.assertNotNull(templateConfig.getEntity(true));
-        Assertions.assertNotNull(templateConfig.getEntity(false));
-
-        templateConfig = new TemplateConfig().disable(TemplateType.ENTITY);
-        Assertions.assertNotNull(templateConfig.getServiceImpl());
-        Assertions.assertNotNull(templateConfig.getService());
-        Assertions.assertNull(templateConfig.getEntity(true));
-        Assertions.assertNull(templateConfig.getEntity(false));
-
-        templateConfig = new TemplateConfig.Builder().all().build().disable(TemplateType.ENTITY);
-        Assertions.assertNotNull(templateConfig.getServiceImpl());
-        Assertions.assertNotNull(templateConfig.getService());
-        Assertions.assertNull(templateConfig.getEntity(true));
-        Assertions.assertNull(templateConfig.getEntity(false));
-
-    }
-
-    @Test
-    void entityTest() {
-        Assertions.assertEquals("/templates/entity.kt", new TemplateConfig().getEntity(true));
-        Assertions.assertEquals("/templates/entity.kt", new TemplateConfig.Builder().all().build().getEntity(true));
-        Assertions.assertEquals("/templates/entity.kt", new TemplateConfig.Builder().entity().build().getEntity(true));
-        Assertions.assertEquals("/templates/entity.java", new TemplateConfig().getEntity(false));
-        Assertions.assertEquals("/templates/entity.java", new TemplateConfig.Builder().all().build().getEntity(false));
-        Assertions.assertEquals("/templates/entity.java", new TemplateConfig.Builder().entity().build().getEntity(false));
-        Assertions.assertEquals("/tm/entity.kt", new TemplateConfig().setEntity("/tm/entity.java").getEntity(true));
-        Assertions.assertEquals("/tm/entity.java", new TemplateConfig().setEntity("/tm/entity.java").getEntity(false));
-        Assertions.assertEquals("/tm/entity.kt", new TemplateConfig.Builder().entity("/tm/entity.java").build().getEntity(true));
-        Assertions.assertEquals("/tm/entity.java", new TemplateConfig.Builder().entity("/tm/entity.java").build().getEntity(false));
-        Assertions.assertEquals("/tm/entity.kt", new TemplateConfig().setEntity("/tm/entity").getEntity(true));
-        Assertions.assertEquals("/tm/entity.kt", new TemplateConfig.Builder().entity("/tm/entity").build().getEntity(true));
-        Assertions.assertEquals("/tm/entity.java", new TemplateConfig().setEntity("/tm/entity").getEntity(false));
-        Assertions.assertEquals("/tm/entity.java", new TemplateConfig.Builder().entity("/tm/entity").build().getEntity(false));
-        Assertions.assertEquals("/tm/entity.kt", new TemplateConfig().setEntity("/tm/entity%s").getEntity(true));
-        Assertions.assertEquals("/tm/entity.kt", new TemplateConfig.Builder().entity("/tm/entity%s").build().getEntity(true));
-        Assertions.assertEquals("/tm/entity.java", new TemplateConfig().setEntity("/tm/entity%s").getEntity(false));
-        Assertions.assertEquals("/tm/entity.java", new TemplateConfig.Builder().entity("/tm/entity%s").build().getEntity(false));
-    }
-
-    @Test
-    void builderTest() {
-        TemplateConfig templateConfig;
-        templateConfig = new TemplateConfig.Builder().entity().service().build();
-        Assertions.assertNotNull(templateConfig.getEntity(true));
-        Assertions.assertNotNull(templateConfig.getEntity(false));
-        Assertions.assertNotNull(templateConfig.getService());
-        Assertions.assertNotNull(templateConfig.getServiceImpl());
-        Assertions.assertNull(templateConfig.getController());
-        Assertions.assertNull(templateConfig.getMapper());
-        Assertions.assertNull(templateConfig.getXml());
-
-        templateConfig = new TemplateConfig.Builder().entity("/tmp/entity").service("/tmp/service.java", "/tmp/serviceImpl.java").build();
-        Assertions.assertNotNull(templateConfig.getEntity(true));
-        Assertions.assertNotNull(templateConfig.getEntity(false));
-        Assertions.assertNotNull(templateConfig.getService());
-        Assertions.assertNotNull(templateConfig.getServiceImpl());
-        Assertions.assertNull(templateConfig.getController());
-        Assertions.assertNull(templateConfig.getMapper());
-        Assertions.assertNull(templateConfig.getXml());
-        Assertions.assertEquals("/tmp/entity.kt", templateConfig.getEntity(true));
-        Assertions.assertEquals("/tmp/entity.java", templateConfig.getEntity(false));
-        Assertions.assertEquals("/tmp/service.java", templateConfig.getService());
-        Assertions.assertEquals("/tmp/serviceImpl.java", templateConfig.getServiceImpl());
-    }
-}

+ 0 - 60
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilderTest.java

@@ -1,60 +0,0 @@
-package com.baomidou.mybatisplus.generator.config.builder;
-
-import com.baomidou.mybatisplus.generator.config.ConstVal;
-import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
-import com.baomidou.mybatisplus.generator.config.PackageConfig;
-import com.baomidou.mybatisplus.generator.config.StrategyConfig;
-import com.baomidou.mybatisplus.generator.config.TemplateConfig;
-import org.h2.Driver;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.Map;
-
-/**
- * @author nieqiurong 2020/10/6.
- */
-public class ConfigBuilderTest {
-
-    private static final DataSourceConfig DATA_SOURCE_CONFIG = new DataSourceConfig()
-        .setUrl("jdbc:h2:mem:test;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE").setDriverName(Driver.class.getName()).setUsername("sa").setPassword("");
-
-    @Test
-    void matcherRegTableTest(){
-        Assertions.assertFalse(ConfigBuilder.matcherRegTable("user"));
-        Assertions.assertFalse(ConfigBuilder.matcherRegTable("USER"));
-        Assertions.assertFalse(ConfigBuilder.matcherRegTable("t_user"));
-        Assertions.assertFalse(ConfigBuilder.matcherRegTable("T_USER"));
-        Assertions.assertFalse(ConfigBuilder.matcherRegTable("t_user_1"));
-        Assertions.assertFalse(ConfigBuilder.matcherRegTable("t_user_12"));
-        Assertions.assertFalse(ConfigBuilder.matcherRegTable("t-user-12"));
-        Assertions.assertTrue(ConfigBuilder.matcherRegTable("t_user_[0-9]"));
-        Assertions.assertTrue(ConfigBuilder.matcherRegTable("t_user_\\d"));
-        Assertions.assertTrue(ConfigBuilder.matcherRegTable("t_user_\\d{3,4}"));
-        Assertions.assertTrue(ConfigBuilder.matcherRegTable("^t_.*"));
-    }
-
-    @Test
-    void pathInfoTest() {
-        ConfigBuilder configBuilder;
-        Map<String, String> pathInfo;
-        configBuilder = new ConfigBuilder(new PackageConfig(), DATA_SOURCE_CONFIG, new StrategyConfig(), new TemplateConfig(), null);
-        pathInfo = configBuilder.getPathInfo();
-        Assertions.assertFalse(pathInfo.isEmpty());
-        Assertions.assertEquals(6, pathInfo.size());
-        Assertions.assertTrue(pathInfo.containsKey(ConstVal.ENTITY_PATH));
-        Assertions.assertTrue(pathInfo.containsKey(ConstVal.CONTROLLER_PATH));
-        Assertions.assertTrue(pathInfo.containsKey(ConstVal.SERVICE_PATH));
-        Assertions.assertTrue(pathInfo.containsKey(ConstVal.SERVICE_IMPL_PATH));
-        Assertions.assertTrue(pathInfo.containsKey(ConstVal.XML_PATH));
-        Assertions.assertTrue(pathInfo.containsKey(ConstVal.MAPPER_PATH));
-
-        configBuilder = new ConfigBuilder(
-            new PackageConfig().setPathInfo(Collections.singletonMap(ConstVal.ENTITY_PATH, "/tmp/code/entity")), DATA_SOURCE_CONFIG, new StrategyConfig(), new TemplateConfig(), null);
-        pathInfo = configBuilder.getPathInfo();
-        Assertions.assertFalse(pathInfo.isEmpty());
-        Assertions.assertEquals(1, pathInfo.size());
-        Assertions.assertTrue(pathInfo.containsKey(ConstVal.ENTITY_PATH));
-    }
-}

+ 0 - 46
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/po/TableFieldTest.java

@@ -1,46 +0,0 @@
-package com.baomidou.mybatisplus.generator.config.po;
-
-import com.baomidou.mybatisplus.generator.config.StrategyConfig;
-import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
-import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- * @author nieqiurong 2020/10/8.
- */
-public class TableFieldTest {
-
-    @Test
-    void convertTest(){
-        TableField tableField;
-        Assertions.assertFalse(new TableField().setName("desc").setPropertyName(new StrategyConfig(), "desc").isConvert());
-        Assertions.assertTrue(new TableField().setName("desc").setPropertyName(new StrategyConfig(), "desc1").isConvert());
-        Assertions.assertTrue(new TableField().setName("DESC").setPropertyName(new StrategyConfig(), "desc").isConvert());
-        Assertions.assertTrue(new TableField().setName("desc").setKeyWords(true).setPropertyName(new StrategyConfig(), "desc").isConvert());
-        Assertions.assertTrue(new TableField().setName("desc").setKeyWords(true).setPropertyName(new StrategyConfig(), "desc1").isConvert());
-        Assertions.assertTrue(new TableField().setName("name").setPropertyName(new StrategyConfig().setEntityTableFieldAnnotationEnable(true), "name").isConvert());
-        Assertions.assertTrue(new TableField().setName("name").setPropertyName(new StrategyConfig().setEntityTableFieldAnnotationEnable(true), "name1").isConvert());
-        Assertions.assertFalse(new TableField().setName("NAME").setPropertyName(new StrategyConfig().setCapitalMode(true), "name").isConvert());
-        Assertions.assertTrue(new TableField().setName("USER_NAME").setPropertyName(new StrategyConfig().setCapitalMode(true), "userName").isConvert());
-        Assertions.assertTrue(new TableField().setName("USER_NAME").setPropertyName(new StrategyConfig().setCapitalMode(true), "userName1").isConvert());
-        Assertions.assertTrue(new TableField().setName("USER_NAME").setPropertyName(new StrategyConfig().setCapitalMode(true), "userName").isConvert());
-        Assertions.assertFalse(new TableField().setName("user_name").setPropertyName(new StrategyConfig().setColumnNaming(NamingStrategy.underline_to_camel), "userName").isConvert());
-        Assertions.assertTrue(new TableField().setName("USER_NAME").setPropertyName(new StrategyConfig().setColumnNaming(NamingStrategy.underline_to_camel), "userName").isConvert());
-        Assertions.assertTrue(new TableField().setName("user_name").setPropertyName(new StrategyConfig().setColumnNaming(NamingStrategy.no_change), "userName").isConvert());
-        Assertions.assertFalse(new TableField().setName("USER_NAME").setPropertyName(new StrategyConfig().setColumnNaming(NamingStrategy.no_change), "USER_NAME").isConvert());
-        Assertions.assertTrue(new TableField().setName("NAME").setPropertyName(new StrategyConfig().setColumnNaming(NamingStrategy.no_change), "name").isConvert());
-        tableField = new TableField().setName("delete").setColumnType(DbColumnType.BOOLEAN).setPropertyName(new StrategyConfig().setEntityBooleanColumnRemoveIsPrefix(true), "delete");
-        Assertions.assertEquals("delete", tableField.getPropertyName());
-        Assertions.assertFalse(tableField.isConvert());
-        tableField = new TableField().setName("delete").setPropertyName("delete", new StrategyConfig().setEntityBooleanColumnRemoveIsPrefix(true), DbColumnType.BOOLEAN);
-        Assertions.assertEquals("delete", tableField.getPropertyName());
-        Assertions.assertFalse(tableField.isConvert());
-        tableField = new TableField().setName("is_delete").setColumnType(DbColumnType.BOOLEAN).setPropertyName(new StrategyConfig().setEntityBooleanColumnRemoveIsPrefix(true), "isDelete");
-        Assertions.assertEquals("delete", tableField.getPropertyName());
-        Assertions.assertTrue(tableField.isConvert());
-        tableField = new TableField().setName("is_delete").setPropertyName("isDelete", new StrategyConfig().setEntityBooleanColumnRemoveIsPrefix(true), DbColumnType.BOOLEAN);
-        Assertions.assertEquals("delete", tableField.getPropertyName());
-        Assertions.assertTrue(tableField.isConvert());
-    }
-}

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

@@ -1,195 +0,0 @@
-package com.baomidou.mybatisplus.generator.config.po;
-
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.Version;
-import com.baomidou.mybatisplus.extension.activerecord.Model;
-import com.baomidou.mybatisplus.generator.config.GlobalConfig;
-import com.baomidou.mybatisplus.generator.config.INameConvert;
-import com.baomidou.mybatisplus.generator.config.StrategyConfig;
-import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
-import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import java.io.Serializable;
-import java.util.Date;
-
-
-/**
- * @author nieqiurong 2020/9/21.
- */
-public class TableInfoTest {
-
-    @Test
-    void getFieldNamesTest() {
-        TableInfo tableInfo;
-        tableInfo = new TableInfo();
-        tableInfo.addFields(new TableField().setColumnName("name"));
-        Assertions.assertEquals(tableInfo.getFieldNames(), "name");
-
-        tableInfo = new TableInfo();
-        tableInfo.addFields(new TableField().setColumnName("name"), new TableField().setColumnName("age"));
-        Assertions.assertEquals(tableInfo.getFieldNames(), "name, age");
-
-        tableInfo = new TableInfo();
-        tableInfo.addFields(new TableField().setColumnName("name"), new TableField().setColumnName("age"), new TableField().setColumnName("phone"));
-        Assertions.assertEquals(tableInfo.getFieldNames(), "name, age, phone");
-    }
-
-    @Test
-    void processTableTest() {
-        TableInfo tableInfo = new TableInfo().setName("user");
-        tableInfo.processTable(new StrategyConfig(), new GlobalConfig());
-        Assertions.assertFalse(tableInfo.isConvert());
-        Assertions.assertEquals("UserMapper", tableInfo.getMapperName());
-        Assertions.assertEquals("UserXml", tableInfo.getXmlName());
-        Assertions.assertEquals("IUserService", tableInfo.getServiceName());
-        Assertions.assertEquals("UserServiceImpl", tableInfo.getServiceImplName());
-        Assertions.assertEquals("UserController", tableInfo.getControllerName());
-
-        tableInfo = new TableInfo().setName("user");
-        tableInfo.processTable(new StrategyConfig(), new GlobalConfig().setEntityName("%sEntity")
-            .setXmlName("%sXml").setMapperName("%sDao").setControllerName("%sAction").setServiceName("%sService").setServiceImplName("%sServiceImp"));
-        Assertions.assertTrue(tableInfo.isConvert());
-        Assertions.assertEquals("UserEntity", tableInfo.getEntityName());
-        Assertions.assertEquals("UserDao", tableInfo.getMapperName());
-        Assertions.assertEquals("UserXml", tableInfo.getXmlName());
-        Assertions.assertEquals("UserService", tableInfo.getServiceName());
-        Assertions.assertEquals("UserServiceImp", tableInfo.getServiceImplName());
-        Assertions.assertEquals("UserAction", tableInfo.getControllerName());
-
-        tableInfo = new TableInfo().setName("user");
-        tableInfo.processTable(new StrategyConfig().setNameConvert(new INameConvert() {
-            @Override
-            public String entityNameConvert(TableInfo tableInfo) {
-                return "E" + tableInfo.getName();
-            }
-
-            @Override
-            public String propertyNameConvert(TableField field) {
-                return field.getName();
-            }
-        }), new GlobalConfig());
-        Assertions.assertTrue(tableInfo.isConvert());
-        Assertions.assertEquals("Euser", tableInfo.getEntityName());
-    }
-
-    @Test
-    void importPackageTest() {
-        TableInfo tableInfo;
-        StrategyConfig strategyConfig;
-
-        tableInfo = new TableInfo().setName("user");
-        tableInfo.importPackage(new StrategyConfig(), new GlobalConfig());
-        Assertions.assertEquals(1, tableInfo.getImportPackages().size());
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(Serializable.class.getName()));
-
-        tableInfo = new TableInfo().setName("user").setConvert(true);
-        tableInfo.importPackage(new StrategyConfig(), new GlobalConfig());
-        Assertions.assertEquals(2, tableInfo.getImportPackages().size());
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(Serializable.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(TableName.class.getName()));
-
-        tableInfo = new TableInfo().setName("user");
-        strategyConfig = new StrategyConfig();
-        tableInfo.importPackage(strategyConfig.setSuperEntityClass("con.baomihua.demo.SuperEntity"), new GlobalConfig());
-        Assertions.assertEquals(1, tableInfo.getImportPackages().size());
-        Assertions.assertFalse(tableInfo.getImportPackages().contains(Serializable.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains("con.baomihua.demo.SuperEntity"));
-
-        tableInfo = new TableInfo().setName("user");
-        strategyConfig = new StrategyConfig();
-        tableInfo.importPackage(strategyConfig, new GlobalConfig().setActiveRecord(true));
-        Assertions.assertEquals(1, tableInfo.getImportPackages().size());
-        Assertions.assertFalse(tableInfo.getImportPackages().contains(Serializable.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(Model.class.getName()));
-
-        strategyConfig = new StrategyConfig();
-        tableInfo = new TableInfo().setName("user");
-        tableInfo.addFields(new TableField().setName("u_id").setPropertyName(strategyConfig, "uid").setColumnType(DbColumnType.LONG).setKeyFlag(true));
-        tableInfo.importPackage(strategyConfig, new GlobalConfig());
-        Assertions.assertEquals(2, tableInfo.getImportPackages().size());
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(Serializable.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(TableId.class.getName()));
-
-        strategyConfig = new StrategyConfig();
-        tableInfo = new TableInfo().setName("user");
-        tableInfo.addFields(new TableField().setName("u_id").setPropertyName(strategyConfig, "uid").setColumnType(DbColumnType.LONG).setKeyFlag(true).setKeyIdentityFlag(true));
-        tableInfo.importPackage(strategyConfig, new GlobalConfig());
-        Assertions.assertEquals(3, tableInfo.getImportPackages().size());
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(Serializable.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(TableId.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(IdType.class.getName()));
-
-        strategyConfig = new StrategyConfig().setLogicDeleteFieldName("delete_flag");
-        tableInfo = new TableInfo().setName("user");
-        tableInfo.addFields(new TableField().setName("u_id").setPropertyName(strategyConfig, "uid").setColumnType(DbColumnType.LONG).setKeyFlag(true));
-        tableInfo.addFields(new TableField().setName("delete_flag").setPropertyName(strategyConfig, "deleteFlag").setColumnType(DbColumnType.BOOLEAN));
-        tableInfo.importPackage(strategyConfig, new GlobalConfig());
-        Assertions.assertEquals(4, tableInfo.getImportPackages().size());
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(Serializable.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(com.baomidou.mybatisplus.annotation.TableField.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(TableLogic.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(TableId.class.getName()));
-
-        tableInfo = new TableInfo().setName("user");
-        tableInfo.addFields(new TableField().setName("name").setPropertyName(strategyConfig, "name").setColumnType(DbColumnType.STRING));
-        tableInfo.importPackage(new StrategyConfig(), new GlobalConfig().setIdType(IdType.ASSIGN_ID));
-        Assertions.assertEquals(1, tableInfo.getImportPackages().size());
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(Serializable.class.getName()));
-
-        tableInfo = new TableInfo().setName("user").setHavePrimaryKey(true);
-        tableInfo.addFields(new TableField().setName("u_id").setPropertyName(strategyConfig, "uid").setColumnType(DbColumnType.LONG).setKeyFlag(true));
-        tableInfo.importPackage(new StrategyConfig(), new GlobalConfig().setIdType(IdType.ASSIGN_ID));
-        Assertions.assertEquals(3, tableInfo.getImportPackages().size());
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(Serializable.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(TableId.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(IdType.class.getName()));
-
-        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().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()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(TableId.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(com.baomidou.mybatisplus.annotation.TableField.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(FieldFill.class.getName()));
-
-        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("version").setPropertyName(strategyConfig, "version").setColumnType(DbColumnType.LONG));
-        tableInfo.importPackage(new StrategyConfig().setVersionFieldName("version"), new GlobalConfig());
-        Assertions.assertEquals(3, tableInfo.getImportPackages().size());
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(Serializable.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(TableId.class.getName()));
-        Assertions.assertTrue(tableInfo.getImportPackages().contains(Version.class.getName()));
-    }
-
-    @Test
-    void setEntityNameTest() {
-        Assertions.assertTrue(new TableInfo().setName("user").setEntityName(new StrategyConfig(), "UserEntity").isConvert());
-        Assertions.assertFalse(new TableInfo().setName("user").setEntityName(new StrategyConfig(), "User").isConvert());
-        Assertions.assertFalse(new TableInfo().setName("USER").setEntityName(new StrategyConfig().setCapitalMode(true), "User").isConvert());
-        Assertions.assertTrue(new TableInfo().setName("USER").setEntityName(new StrategyConfig().setCapitalMode(true), "UserEntity").isConvert());
-        Assertions.assertTrue(new TableInfo().setName("test_user").setEntityName(new StrategyConfig().setNaming(NamingStrategy.no_change), "TestUser").isConvert());
-        Assertions.assertFalse(new TableInfo().setName("user").setEntityName(new StrategyConfig().setNaming(NamingStrategy.no_change), "User").isConvert());
-        Assertions.assertFalse(new TableInfo().setName("test_user").setEntityName(new StrategyConfig().setNaming(NamingStrategy.underline_to_camel), "TestUser").isConvert());
-        Assertions.assertTrue(new TableInfo().setName("TEST_USER").setEntityName(new StrategyConfig().setNaming(NamingStrategy.underline_to_camel), "TestUser").isConvert());
-    }
-
-    @Test
-    void getFileNameTest() {
-        TableInfo tableInfo = new TableInfo();
-        Assertions.assertEquals("UserEntity", tableInfo.getFileName("User", "", () -> "UserEntity"));
-        Assertions.assertEquals("UserEntity", tableInfo.getFileName("User", null, () -> "UserEntity"));
-        Assertions.assertEquals("UserTable", tableInfo.getFileName("User", "%sTable", () -> "UserEntity"));
-        Assertions.assertEquals("UserTable", tableInfo.getFileName("User", "UserTable", () -> "UserEntity"));
-    }
-
-}

+ 0 - 9
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/rules/NamingStrategyTest.java

@@ -14,14 +14,5 @@ public class NamingStrategyTest {
         Assertions.assertEquals(NamingStrategy.removePrefix("test_ab", new HashSet<>(Arrays.asList("t_", "test"))), "_ab");
     }
 
-    @Test
-    void underlineToCamelTest(){
-        Assertions.assertEquals(NamingStrategy.underlineToCamel("Aid"), "aid");
-        Assertions.assertEquals(NamingStrategy.underlineToCamel("test_id"), "testId");
-        Assertions.assertEquals(NamingStrategy.underlineToCamel("TEST_ID"), "testId");
-        Assertions.assertEquals(NamingStrategy.underlineToCamel("Test_id"), "testId");
-        Assertions.assertEquals(NamingStrategy.underlineToCamel("Test_ID"), "testId");
-        Assertions.assertEquals(NamingStrategy.underlineToCamel("TeSt_id"), "testId");
-    }
 
 }

+ 0 - 66
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/engine/TemplateEngineTest.java

@@ -1,66 +0,0 @@
-package com.baomidou.mybatisplus.generator.engine;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
-import com.baomidou.mybatisplus.generator.config.GlobalConfig;
-import com.baomidou.mybatisplus.generator.config.PackageConfig;
-import com.baomidou.mybatisplus.generator.config.StrategyConfig;
-import com.baomidou.mybatisplus.generator.config.TemplateConfig;
-import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
-import com.baomidou.mybatisplus.generator.config.po.LikeTable;
-import com.baomidou.mybatisplus.generator.config.po.TableInfo;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import java.util.Map;
-
-/**
- * @author nieqiurong 2020/10/11.
- */
-public class TemplateEngineTest {
-
-
-    private void compatibleAssert(ConfigBuilder configBuilder){
-        VelocityTemplateEngine velocityTemplateEngine = new VelocityTemplateEngine();
-        velocityTemplateEngine.setConfigBuilder(configBuilder);
-        Map<String, Object> objectMap = velocityTemplateEngine.getObjectMap(new TableInfo());
-        Assertions.assertEquals(Boolean.TRUE, objectMap.get("enableCache"));
-        Assertions.assertEquals(Boolean.TRUE, objectMap.get("baseResultMap"));
-        Assertions.assertEquals(Boolean.TRUE, objectMap.get("baseColumnList"));
-        Assertions.assertEquals(Boolean.TRUE, objectMap.get("activeRecord"));
-        Assertions.assertEquals(IdType.INPUT.toString(), objectMap.get("idType"));
-    }
-
-    @Test
-    void compatibleTest(){
-        DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder("jdbc:h2:mem:test;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE", "sa", "").build();
-        compatibleAssert(new ConfigBuilder(new PackageConfig(), dataSourceConfig,
-            new StrategyConfig.Builder().likeTable(new LikeTable("USER")).build(),
-            new TemplateConfig.Builder().build(),
-            new GlobalConfig().setActiveRecord(true).setBaseColumnList(true).setEnableCache(true).setBaseResultMap(true).setIdType(IdType.INPUT)));
-
-        compatibleAssert(new ConfigBuilder(new PackageConfig(), dataSourceConfig,
-            new StrategyConfig.Builder().likeTable(new LikeTable("USER")).build(),
-            new TemplateConfig.Builder().build(),
-            new GlobalConfig.Builder().activeRecord(true).baseColumnList(true).enableCache(true).baseResultMap(true).idType(IdType.INPUT).build()));
-
-        compatibleAssert(new ConfigBuilder(new PackageConfig(), dataSourceConfig,
-            new StrategyConfig.Builder().likeTable(new LikeTable("USER"))
-                .entityBuilder().activeRecord(true).idType(IdType.INPUT)
-                .mapperBuilder().baseResultMap(true).baseColumnList(true).enableXmlCache(true)
-                .build(),
-            new TemplateConfig.Builder().build(),
-            new GlobalConfig.Builder().build()));
-
-        compatibleAssert(new ConfigBuilder(new PackageConfig(), dataSourceConfig,
-            new StrategyConfig.Builder().likeTable(new LikeTable("USER"))
-                .entityBuilder().activeRecord(true).idType(IdType.INPUT)
-                .mapperBuilder().baseResultMap(true).baseColumnList(true).enableXmlCache(true)
-                .build(),
-            new TemplateConfig.Builder().build(),
-            new GlobalConfig.Builder().activeRecord(false).baseColumnList(false).enableCache(false).baseResultMap(false).idType(IdType.ASSIGN_ID).build()));
-
-
-    }
-
-}

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

@@ -24,7 +24,6 @@ import com.baomidou.mybatisplus.generator.config.PackageConfig;
 import com.baomidou.mybatisplus.generator.config.StrategyConfig;
 import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
 import com.mysql.cj.jdbc.Driver;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -33,7 +32,6 @@ import org.junit.jupiter.api.Test;
  * @author K神
  * @since 2017/12/29
  */
-@Disabled
 class CodeGeneratorTest {
 
     /**
@@ -47,7 +45,7 @@ class CodeGeneratorTest {
     /**
      * 是否去掉生成实体的属性名前缀
      */
-    private String[] fieldPrefix = new String[]{};
+    private String[] fieldPrefix = null;
     /**
      * 生成的Service 接口类名是否以I开头
      * <p>默认是以I开头</p>

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

@@ -22,7 +22,6 @@ import com.baomidou.mybatisplus.generator.InjectionConfig;
 import com.baomidou.mybatisplus.generator.config.*;
 import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
 import com.mysql.cj.jdbc.Driver;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import java.util.HashMap;
@@ -34,7 +33,6 @@ import java.util.Map;
  * @author K神
  * @since 2017/12/29
  */
-@Disabled
 class CodeGeneratorWithTemplateTest {
 
     /**
@@ -48,7 +46,7 @@ class CodeGeneratorWithTemplateTest {
     /**
      * 是否去掉生成实体的属性名前缀
      */
-    private String[] fieldPrefix = new String[]{};
+    private String[] fieldPrefix = null;
     /**
      * 生成的Service 接口类名是否以I开头
      * <p>默认是以I开头</p>

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

@@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test;
  */
 class H2CodeGeneratorTest {
 
-    private static final String outPutDir = System.getProperty("os.name").toLowerCase().contains("windows") ? "D://tmp" : "/tmp";
+    private static String outPutDir = System.getProperty("os.name").toLowerCase().contains("windows") ? "D://tmp" : "/tmp";
 
     private DataSourceConfig dataSourceConfig() {
         String dbUrl = "jdbc:h2:mem:test;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE";

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

@@ -44,6 +44,10 @@ public class MysqlGenerator extends GeneratorTest {
      */
     public static void main(String[] args) {
         int result = scanner();
+        // 自定义需要填充的字段
+        List<TableFill> tableFillList = new ArrayList<>();
+        tableFillList.add(new TableFill("ASDD_SS", FieldFill.INSERT_UPDATE));
+
         // 代码生成器
         AutoGenerator mpg = new AutoGenerator().setGlobalConfig(
             // 全局配置
@@ -107,8 +111,8 @@ public class MysqlGenerator extends GeneratorTest {
                 // 自定义实体父类
                 // .setSuperEntityClass("com.baomidou.demo.TestEntity")
                 // 自定义实体,公共字段
-                .setSuperEntityColumns("test_id")
-                .setTableFillList(Collections.singletonList(new TableFill("ASDD_SS", FieldFill.INSERT_UPDATE)))
+                .setSuperEntityColumns(new String[]{"test_id"})
+                .setTableFillList(tableFillList)
                 .setEntityBooleanColumnRemoveIsPrefix(true)
             // 自定义 mapper 父类
             // .setSuperMapperClass("com.baomidou.demo.TestMapper")

+ 4 - 155
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/StrategyConfigTest.java

@@ -15,16 +15,11 @@
  */
 package com.baomidou.mybatisplus.test.generator;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.List;
 import java.util.Set;
 
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.generator.config.INameConvert;
-import com.baomidou.mybatisplus.generator.config.po.TableField;
-import com.baomidou.mybatisplus.generator.config.po.TableFill;
-import com.baomidou.mybatisplus.generator.config.po.TableInfo;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
 import lombok.Data;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
@@ -116,159 +111,13 @@ class StrategyConfigTest {
         Assertions.assertTrue(strategyConfig.startsWithTablePrefix("t_name"));
     }
 
-    @Test
-    void addTableFillsTest() {
-        TableFill tableFill = new TableFill("test", FieldFill.INSERT);
-        List<TableFill> tableFillList = new ArrayList<>();
-        tableFillList.add(tableFill);
-        StrategyConfig strategyConfig = new StrategyConfig();
-        strategyConfig.setTableFillList(tableFillList);
-        Assertions.assertFalse(strategyConfig.getTableFillList().isEmpty());
-        strategyConfig = new StrategyConfig();
-        strategyConfig.entityBuilder().addTableFills(tableFill);
-        Assertions.assertFalse(strategyConfig.getTableFillList().isEmpty());
-    }
-
-    @Test
-    void entityNameConvertTest() {
-        StrategyConfig strategyConfig;
-        TableInfo tableInfo = new TableInfo();
-        tableInfo.setName("t_user");
-
-        strategyConfig = new StrategyConfig();
-        Assertions.assertEquals("T_user", strategyConfig.getNameConvert().entityNameConvert(tableInfo));
-        strategyConfig.setTablePrefix("t_", "a_");
-        Assertions.assertEquals("User", strategyConfig.getNameConvert().entityNameConvert(tableInfo));
-
-        strategyConfig = new StrategyConfig();
-        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
-        Assertions.assertEquals("TUser", strategyConfig.getNameConvert().entityNameConvert(tableInfo));
-
-        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
-        strategyConfig.setTablePrefix("t_", "a_");
-        Assertions.assertEquals("User", strategyConfig.getNameConvert().entityNameConvert(tableInfo));
-
-        strategyConfig = new StrategyConfig();
-        strategyConfig.setNameConvert(new INameConvert() {
-            @Override
-            public String entityNameConvert(TableInfo tableInfo) {
-                return "aaaa";
-            }
-
-            @Override
-            public String propertyNameConvert(TableField field) {
-                return "bbbb";
-            }
-        });
-        Assertions.assertEquals("aaaa", strategyConfig.getNameConvert().entityNameConvert(tableInfo));
-    }
-
-    @Test
-    void propertyNameConvertTest() {
-        StrategyConfig strategyConfig;
-        TableField tableField = new TableField();
-        tableField.setName("c_user_name");
-
-        strategyConfig = new StrategyConfig();
-        Assertions.assertEquals("c_user_name", strategyConfig.getNameConvert().propertyNameConvert(tableField));
-        strategyConfig.setTablePrefix("t_", "c_");
-        Assertions.assertEquals("user_name", strategyConfig.getNameConvert().propertyNameConvert(tableField));
-
-        strategyConfig = new StrategyConfig();
-        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
-        Assertions.assertEquals("cUserName", strategyConfig.getNameConvert().propertyNameConvert(tableField));
-
-        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
-        strategyConfig.setTablePrefix("t_", "c_");
-        Assertions.assertEquals("userName", strategyConfig.getNameConvert().propertyNameConvert(tableField));
-
-        strategyConfig = new StrategyConfig();
-        strategyConfig.setNameConvert(new INameConvert() {
-            @Override
-            public String entityNameConvert(TableInfo tableInfo) {
-                return "aaaa";
-            }
-
-            @Override
-            public String propertyNameConvert(TableField field) {
-                return "bbbb";
-            }
-        });
-        Assertions.assertEquals("bbbb", strategyConfig.getNameConvert().propertyNameConvert(tableField));
-    }
-
-    @Test
-    void matchExcludeTableTest(){
-        StrategyConfig strategyConfig = new StrategyConfig();
-        strategyConfig.setExclude("system", "user_1", "test[a|b]");
-        Assertions.assertTrue(strategyConfig.matchExcludeTable("system"));
-        Assertions.assertFalse(strategyConfig.matchExcludeTable("test_exclude"));
-        Assertions.assertTrue(strategyConfig.matchExcludeTable("testa"));
-        Assertions.assertTrue(strategyConfig.matchExcludeTable("testb"));
-        Assertions.assertFalse(strategyConfig.matchExcludeTable("testc"));
-    }
-
-    @Test
-    void matchIncludeTableTest(){
-        StrategyConfig strategyConfig = new StrategyConfig();
-        strategyConfig.setInclude("system", "user_1", "test[a|b]");
-        Assertions.assertTrue(strategyConfig.matchIncludeTable("system"));
-        Assertions.assertFalse(strategyConfig.matchIncludeTable("test_exclude"));
-        Assertions.assertTrue(strategyConfig.matchIncludeTable("testa"));
-        Assertions.assertTrue(strategyConfig.matchIncludeTable("testb"));
-        Assertions.assertFalse(strategyConfig.matchIncludeTable("testc"));
-    }
-
-    @Test
-    void isCapitalModeNamingTest() {
-        Assertions.assertFalse(new StrategyConfig().isCapitalModeNaming("T_USER"));
-        Assertions.assertFalse(new StrategyConfig().setCapitalMode(true).isCapitalModeNaming("user"));
-        Assertions.assertFalse(new StrategyConfig().setCapitalMode(true).isCapitalModeNaming("user_name"));
-        Assertions.assertTrue(new StrategyConfig().setCapitalMode(true).isCapitalModeNaming("USER_NAME"));
-        Assertions.assertTrue(new StrategyConfig().setCapitalMode(true).isCapitalModeNaming("T_USER"));
-        Assertions.assertTrue(new StrategyConfig().setCapitalMode(true).isCapitalModeNaming("NAME"));
-    }
-
-    private void buildAssert(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.controllerBuilder().get().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")
-        ;
-        buildAssert(strategyConfig);
-        strategyConfig = new StrategyConfig.Builder().skipView(true)
-            .entityBuilder().chainModel(true).lombok(true).serialVersionUID(true)
-            .controllerBuilder().superClass("com.baomidou.mp.SuperController").hyphenStyle(true).restStyle(true)
-            .mapperBuilder().superClass("com.baomidou.mp.SuperMapper").build();
-        buildAssert(strategyConfig);
-    }
-
     @Data
     static class SuperBean {
 
-        @com.baomidou.mybatisplus.annotation.TableId(value = "test_id")
+        @TableId(value = "test_id")
         private String id;
 
-        @com.baomidou.mybatisplus.annotation.TableField(value = "aa_name")
+        @TableField(value = "aa_name")
         private String name;
 
         private String ok;