소스 검색

全局配置构建.

nieqiurong 4 년 전
부모
커밋
172c18539e

+ 360 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/GlobalConfig.java

@@ -16,6 +16,8 @@
 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;
@@ -49,6 +51,7 @@ public class GlobalConfig {
     /**
      * 是否在xml中添加二级缓存配置
      */
+    @Deprecated
     private boolean enableCache = false;
 
     /**
@@ -69,11 +72,13 @@ public class GlobalConfig {
     /**
      * 开启 ActiveRecord 模式
      */
+    @Deprecated
     private boolean activeRecord = false;
 
     /**
      * 开启 BaseResultMap
      */
+    @Deprecated
     private boolean baseResultMap = false;
 
     /**
@@ -84,6 +89,7 @@ public class GlobalConfig {
     /**
      * 开启 baseColumnList
      */
+    @Deprecated
     private boolean baseColumnList = false;
     /**
      * 各层文件名称方式,例如: %sAction 生成 UserAction
@@ -95,8 +101,362 @@ 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;
+    }
+
+    /**
+     * 全局配置构建
+     *
+     * @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;
+        }
+    }
 }

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

@@ -1,3 +1,18 @@
+/*
+ * 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;

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

@@ -1,3 +1,18 @@
+/*
+ * 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;

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

@@ -1,5 +1,21 @@
+/*
+ * 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;
@@ -116,6 +132,20 @@ public class Entity {
      */
     private NamingStrategy columnNaming = null;
 
+    /**
+     * 开启 ActiveRecord 模式
+     *
+     * @since 3.4.1
+     */
+    private boolean activeRecord;
+
+    /**
+     * 指定生成的主键的ID类型
+     *
+     * @since 3.4.1
+     */
+    private IdType idType;
+
     /**
      * <p>
      * 父类 Class 反射属性转换为公共字段
@@ -333,6 +363,30 @@ public class Entity {
             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;
         }

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

@@ -1,3 +1,18 @@
+/*
+ * 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;
@@ -21,6 +36,27 @@ public class 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();
@@ -51,6 +87,41 @@ public class Mapper {
             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;
         }

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

@@ -1,3 +1,18 @@
+/*
+ * 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;

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

@@ -15,6 +15,7 @@
  */
 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;
@@ -210,17 +211,18 @@ public abstract class AbstractTemplateEngine {
         objectMap.put("package", config.getPackageConfig().getPackageInfo());
         GlobalConfig globalConfig = config.getGlobalConfig();
         objectMap.put("author", globalConfig.getAuthor());
-        objectMap.put("idType", globalConfig.getIdType() == null ? null : globalConfig.getIdType().toString());
+        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());
+        objectMap.put("activeRecord", globalConfig.isActiveRecord() || config.getStrategyConfig().entity().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());
-        objectMap.put("baseResultMap", globalConfig.isBaseResultMap());
-        objectMap.put("baseColumnList", globalConfig.isBaseColumnList());
+        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("entity", tableInfo.getEntityName());
         objectMap.put("entitySerialVersionUID", config.getStrategyConfig().entity().isSerialVersionUID());
         objectMap.put("entityColumnConstant", config.getStrategyConfig().entity().isColumnConstant());

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

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

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

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

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

@@ -229,7 +229,7 @@ class StrategyConfigTest {
         Assertions.assertTrue(new StrategyConfig().setCapitalMode(true).isCapitalModeNaming("NAME"));
     }
 
-    private void builderValidate(StrategyConfig strategyConfig){
+    private void buildAssert(StrategyConfig strategyConfig){
         Assertions.assertTrue(strategyConfig.isSkipView());
         Assertions.assertTrue(strategyConfig.isChainModel());
         Assertions.assertTrue(strategyConfig.entity().isChain());
@@ -254,12 +254,12 @@ class StrategyConfigTest {
             .setEntitySerialVersionUID(true).setControllerMappingHyphenStyle(true).setRestControllerStyle(true)
             .setSuperControllerClass("com.baomidou.mp.SuperController").setSuperMapperClass("com.baomidou.mp.SuperMapper")
         ;
-        builderValidate(strategyConfig);
+        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();
-        builderValidate(strategyConfig);
+        buildAssert(strategyConfig);
     }
 
     @Data