Przeglądaj źródła

移除 [MybatisMapperRefresh,PackageHelper] MybatisSqlSessionFactoryBean scan class 使用内部函数

miemie 5 lat temu
rodzic
commit
0af62b220e

+ 0 - 279
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/spring/MybatisMapperRefresh.java

@@ -1,279 +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.extension.spring;
-
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
-import com.baomidou.mybatisplus.core.toolkit.SystemClock;
-import org.apache.ibatis.binding.MapperRegistry;
-import org.apache.ibatis.builder.xml.XMLMapperBuilder;
-import org.apache.ibatis.builder.xml.XMLMapperEntityResolver;
-import org.apache.ibatis.executor.ErrorContext;
-import org.apache.ibatis.executor.keygen.SelectKeyGenerator;
-import org.apache.ibatis.io.Resources;
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.logging.LogFactory;
-import org.apache.ibatis.parsing.XNode;
-import org.apache.ibatis.parsing.XPathParser;
-import org.apache.ibatis.session.Configuration;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.UrlResource;
-import org.springframework.util.ResourceUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.*;
-
-/**
- * 切莫用于生产环境(后果自负)
- * <p>Mybatis 映射文件热加载(发生变动后自动重新加载).</p>
- * <p>方便开发时使用,不用每次修改xml文件后都要去重启应用.</p>
- *
- * @author nieqiurong
- * @since 2016-08-25
- * @deprecated 2018-11-26
- */
-@Deprecated
-public class MybatisMapperRefresh implements Runnable {
-
-    private static final Log logger = LogFactory.getLog(MybatisMapperRefresh.class);
-    /**
-     * 记录jar包存在的mapper
-     */
-    private static final Map<String, List<Resource>> JAR_MAPPER = new HashMap<>();
-    private final SqlSessionFactory sqlSessionFactory;
-    private final Resource[] mapperLocations;
-    /**
-     * 是否开启刷新mapper
-     */
-    private final boolean enabled;
-    private Long beforeTime = 0L;
-    private Configuration configuration;
-    /**
-     * xml文件目录
-     */
-    private Set<String> fileSet;
-    /**
-     * 延迟加载时间
-     */
-    private int delaySeconds = 10;
-    /**
-     * 刷新间隔时间
-     */
-    private int sleepSeconds = 20;
-
-    public MybatisMapperRefresh(Resource[] mapperLocations, SqlSessionFactory sqlSessionFactory, int delaySeconds,
-                                int sleepSeconds, boolean enabled) {
-        this.mapperLocations = mapperLocations.clone();
-        this.sqlSessionFactory = sqlSessionFactory;
-        this.delaySeconds = delaySeconds;
-        this.enabled = enabled;
-        this.sleepSeconds = sleepSeconds;
-        this.configuration = sqlSessionFactory.getConfiguration();
-        this.run();
-    }
-
-    public MybatisMapperRefresh(Resource[] mapperLocations, SqlSessionFactory sqlSessionFactory, boolean enabled) {
-        this.mapperLocations = mapperLocations.clone();
-        this.sqlSessionFactory = sqlSessionFactory;
-        this.enabled = enabled;
-        this.configuration = sqlSessionFactory.getConfiguration();
-        this.run();
-    }
-
-    @Override
-    public void run() {
-        /*
-         * 启动 XML 热加载
-         */
-        if (enabled) {
-            beforeTime = SystemClock.now();
-            final MybatisMapperRefresh runnable = this;
-            new Thread(() -> {
-                if (fileSet == null) {
-                    fileSet = new HashSet<>();
-                    if (mapperLocations != null) {
-                        for (Resource mapperLocation : mapperLocations) {
-                            try {
-                                if (ResourceUtils.isJarURL(mapperLocation.getURL())) {
-                                    String key = new UrlResource(ResourceUtils.extractJarFileURL(mapperLocation.getURL()))
-                                        .getFile().getPath();
-                                    fileSet.add(key);
-                                    if (JAR_MAPPER.get(key) != null) {
-                                        JAR_MAPPER.get(key).add(mapperLocation);
-                                    } else {
-                                        List<Resource> resourcesList = new ArrayList<>();
-                                        resourcesList.add(mapperLocation);
-                                        JAR_MAPPER.put(key, resourcesList);
-                                    }
-                                } else {
-                                    fileSet.add(mapperLocation.getFile().getPath());
-                                }
-                            } catch (IOException ioException) {
-                                ioException.printStackTrace();
-                            }
-                        }
-                    }
-                }
-                try {
-                    Thread.sleep(delaySeconds * 1000);
-                } catch (InterruptedException interruptedException) {
-                    interruptedException.printStackTrace();
-                }
-                do {
-                    try {
-                        for (String filePath : fileSet) {
-                            File file = new File(filePath);
-                            if (file.isFile() && file.lastModified() > beforeTime) {
-                                List<Resource> removeList = JAR_MAPPER.get(filePath);
-                                if (removeList != null && !removeList.isEmpty()) {
-                                    for (Resource resource : removeList) {
-                                        runnable.refresh(resource);
-                                    }
-                                } else {
-                                    runnable.refresh(new FileSystemResource(file));
-                                }
-                            }
-                        }
-                        beforeTime = SystemClock.now();
-                    } catch (Exception exception) {
-                        exception.printStackTrace();
-                    }
-                    try {
-                        Thread.sleep(sleepSeconds * 1000);
-                    } catch (InterruptedException interruptedException) {
-                        interruptedException.printStackTrace();
-                    }
-
-                } while (true);
-            }, "mybatis-plus MapperRefresh").start();
-        }
-    }
-
-    /**
-     * 刷新mapper
-     */
-    @SuppressWarnings("rawtypes")
-    private void refresh(Resource resource) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
-        this.configuration = sqlSessionFactory.getConfiguration();
-        boolean isSupper = configuration.getClass().getSuperclass() == Configuration.class;
-        try {
-            Field loadedResourcesField = isSupper ? configuration.getClass().getSuperclass().getDeclaredField("loadedResources")
-                : configuration.getClass().getDeclaredField("loadedResources");
-            loadedResourcesField.setAccessible(true);
-            Set loadedResourcesSet = ((Set) loadedResourcesField.get(configuration));
-            XPathParser xPathParser = new XPathParser(resource.getInputStream(), true, configuration.getVariables(),
-                new XMLMapperEntityResolver());
-            XNode context = xPathParser.evalNode("/mapper");
-            String namespace = context.getStringAttribute("namespace");
-            Field field = MapperRegistry.class.getDeclaredField("knownMappers");
-            field.setAccessible(true);
-            Map mapConfig = (Map) field.get(configuration.getMapperRegistry());
-            mapConfig.remove(Resources.classForName(namespace));
-            loadedResourcesSet.remove(resource.toString());
-            configuration.getCacheNames().remove(namespace);
-            cleanParameterMap(context.evalNodes("/mapper/parameterMap"), namespace);
-            cleanResultMap(context.evalNodes("/mapper/resultMap"), namespace);
-            cleanKeyGenerators(context.evalNodes("insert|update"), namespace);
-            cleanSqlElement(context.evalNodes("/mapper/sql"), namespace);
-            XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resource.getInputStream(),
-                sqlSessionFactory.getConfiguration(),
-                resource.toString(), sqlSessionFactory.getConfiguration().getSqlFragments());
-            xmlMapperBuilder.parse();
-            logger.debug("refresh: '" + resource + "', success!");
-        } catch (IOException e) {
-            logger.error("Refresh IOException :" + e.getMessage());
-        } finally {
-            ErrorContext.instance().reset();
-        }
-    }
-
-    /**
-     * 清理parameterMap
-     *
-     * @param list      ignore
-     * @param namespace ignore
-     */
-    @SuppressWarnings("unlikely-arg-type")
-	private void cleanParameterMap(List<XNode> list, String namespace) {
-        for (XNode parameterMapNode : list) {
-            String id = parameterMapNode.getStringAttribute("id");
-            configuration.getParameterMaps().remove(namespace + StringPool.DOT + id);
-        }
-    }
-
-    /**
-     * 清理resultMap
-     *
-     * @param list      ignore
-     * @param namespace ignore
-     */
-    private void cleanResultMap(List<XNode> list, String namespace) {
-        for (XNode resultMapNode : list) {
-            String id = resultMapNode.getStringAttribute("id", resultMapNode.getValueBasedIdentifier());
-            configuration.getResultMapNames().remove(id);
-            configuration.getResultMapNames().remove(namespace + StringPool.DOT + id);
-            clearResultMap(resultMapNode, namespace);
-        }
-    }
-
-    private void clearResultMap(XNode xNode, String namespace) {
-        for (XNode resultChild : xNode.getChildren()) {
-            if ("association".equals(resultChild.getName()) || "collection".equals(resultChild.getName())
-                || "case".equals(resultChild.getName())) {
-                if (resultChild.getStringAttribute("select") == null) {
-                    configuration.getResultMapNames().remove(
-                        resultChild.getStringAttribute("id", resultChild.getValueBasedIdentifier()));
-                    configuration.getResultMapNames().remove(
-                        namespace + StringPool.DOT + resultChild.getStringAttribute("id", resultChild.getValueBasedIdentifier()));
-                    if (resultChild.getChildren() != null && !resultChild.getChildren().isEmpty()) {
-                        clearResultMap(resultChild, namespace);
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * 清理selectKey
-     *
-     * @param list      ignore
-     * @param namespace ignore
-     */
-    private void cleanKeyGenerators(List<XNode> list, String namespace) {
-        for (XNode context : list) {
-            String id = context.getStringAttribute("id");
-            configuration.getKeyGeneratorNames().remove(id + SelectKeyGenerator.SELECT_KEY_SUFFIX);
-            configuration.getKeyGeneratorNames().remove(namespace + StringPool.DOT + id + SelectKeyGenerator.SELECT_KEY_SUFFIX);
-        }
-    }
-
-    /**
-     * 清理sql节点缓存
-     *
-     * @param list      ignore
-     * @param namespace ignore
-     */
-    private void cleanSqlElement(List<XNode> list, String namespace) {
-        for (XNode context : list) {
-            String id = context.getStringAttribute("id");
-            configuration.getSqlFragments().remove(id);
-            configuration.getSqlFragments().remove(namespace + StringPool.DOT + id);
-        }
-    }
-}

+ 36 - 26
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/spring/MybatisSqlSessionFactoryBean.java

@@ -21,11 +21,11 @@ import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder;
 import com.baomidou.mybatisplus.core.MybatisXMLConfigBuilder;
 import com.baomidou.mybatisplus.core.config.GlobalConfig;
 import com.baomidou.mybatisplus.core.enums.IEnum;
+import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
 import com.baomidou.mybatisplus.core.toolkit.Assert;
 import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.extension.handlers.MybatisEnumTypeHandler;
-import com.baomidou.mybatisplus.extension.toolkit.PackageHelper;
 import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
 import lombok.Setter;
 import org.apache.ibatis.builder.xml.XMLMapperBuilder;
@@ -83,7 +83,8 @@ import static org.springframework.util.StringUtils.tokenizeToStringArray;
 /**
  * 拷贝类 {@link SqlSessionFactoryBean} 修改方法 buildSqlSessionFactory() 加载自定义
  * <p> MybatisXmlConfigBuilder </p>
- * <p> 移除 sqlSessionFactoryBuilder 属性,强制使用 MybatisSqlSessionFactoryBuilder </p>
+ * <p> 移除 sqlSessionFactoryBuilder 属性,强制使用 `new MybatisSqlSessionFactoryBuilder()` </p>
+ * <p> 移除 environment 属性,强制使用 `MybatisSqlSessionFactoryBean.class.getSimpleName()` </p>
  *
  * @author hubin
  * @since 2017-01-04
@@ -110,10 +111,6 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
 
     private SqlSessionFactory sqlSessionFactory;
 
-    // TODO 默认值改为 MybatisSqlSessionFactoryBean.class.getSimpleName();
-    // EnvironmentAware requires spring 3.1
-    private String environment = MybatisSqlSessionFactoryBean.class.getSimpleName();
-
     private boolean failFast;
 
     private Interceptor[] plugins;
@@ -401,14 +398,23 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
     }
 
     /**
-     * <b>NOTE:</b> This class <em>overrides</em> any {@code Environment} you have set in the MyBatis
-     * config file. This is used only as a placeholder name. The default value is
-     * {@code SqlSessionFactoryBean.class.getSimpleName()}.
+     * Set scripting language drivers.
      *
-     * @param environment the environment name
+     * @param scriptingLanguageDrivers scripting language drivers
+     * @since 2.0.2
      */
-    public void setEnvironment(String environment) {
-        this.environment = environment;
+    public void setScriptingLanguageDrivers(LanguageDriver... scriptingLanguageDrivers) {
+        this.scriptingLanguageDrivers = scriptingLanguageDrivers;
+    }
+
+    /**
+     * Set a default scripting language driver class.
+     *
+     * @param defaultScriptingLanguageDriver A default scripting language driver class
+     * @since 2.0.2
+     */
+    public void setDefaultScriptingLanguageDriver(Class<? extends LanguageDriver> defaultScriptingLanguageDriver) {
+        this.defaultScriptingLanguageDriver = defaultScriptingLanguageDriver;
     }
 
     /**
@@ -470,21 +476,25 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
             Set<Class<?>> classes;
             if (typeEnumsPackage.contains(StringPool.STAR) && !typeEnumsPackage.contains(StringPool.COMMA)
                 && !typeEnumsPackage.contains(StringPool.SEMICOLON)) {
-                classes = PackageHelper.scanTypePackage(typeEnumsPackage);
+                classes = scanClasses(typeEnumsPackage, null);
                 if (classes.isEmpty()) {
                     LOGGER.warn(() -> "Can't find class in '[" + typeEnumsPackage + "]' package. Please check your configuration.");
                 }
             } else {
+                classes = new HashSet<>();
                 String[] typeEnumsPackageArray = tokenizeToStringArray(this.typeEnumsPackage,
                     ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
                 Assert.notNull(typeEnumsPackageArray, "not find typeEnumsPackage:" + typeEnumsPackage);
-                classes = new HashSet<>();
                 Stream.of(typeEnumsPackageArray).forEach(typePackage -> {
-                    Set<Class<?>> scanTypePackage = PackageHelper.scanTypePackage(typePackage);
-                    if (scanTypePackage.isEmpty()) {
-                        LOGGER.warn(() -> "Can't find class in '[" + typePackage + "]' package. Please check your configuration.");
-                    } else {
-                        classes.addAll(PackageHelper.scanTypePackage(typePackage));
+                    try {
+                        Set<Class<?>> scanTypePackage = scanClasses(typePackage, null);
+                        if (scanTypePackage.isEmpty()) {
+                            LOGGER.warn(() -> "Can't find class in '[" + typePackage + "]' package. Please check your configuration.");
+                        } else {
+                            classes.addAll(scanTypePackage);
+                        }
+                    } catch (IOException e) {
+                        throw new MybatisPlusException("Cannot scan class in '[" + typePackage + "]' package", e);
                     }
                 });
             }
@@ -501,8 +511,9 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
         Optional.ofNullable(this.vfs).ifPresent(targetConfiguration::setVfsImpl);
 
         if (hasLength(this.typeAliasesPackage)) {
-            scanClasses(this.typeAliasesPackage, this.typeAliasesSuperType)
-                .forEach(targetConfiguration.getTypeAliasRegistry()::registerAlias);
+            scanClasses(this.typeAliasesPackage, this.typeAliasesSuperType).stream()
+                .filter(clazz -> !clazz.isAnonymousClass()).filter(clazz -> !clazz.isInterface())
+                .filter(clazz -> !clazz.isMemberClass()).forEach(targetConfiguration.getTypeAliasRegistry()::registerAlias);
         }
 
         if (!isEmpty(this.typeAliases)) {
@@ -520,9 +531,8 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
         }
 
         if (hasLength(this.typeHandlersPackage)) {
-            scanClasses(this.typeHandlersPackage, TypeHandler.class).stream()
-                .filter(clazz -> !clazz.isInterface())
-                .filter(clazz -> !Modifier.isAbstract(clazz.getModifiers()))
+            scanClasses(this.typeHandlersPackage, TypeHandler.class).stream().filter(clazz -> !clazz.isAnonymousClass())
+                .filter(clazz -> !clazz.isInterface()).filter(clazz -> !Modifier.isAbstract(clazz.getModifiers()))
                 .filter(clazz -> ClassUtils.getConstructorIfAvailable(clazz) != null)
                 .forEach(targetConfiguration.getTypeHandlerRegistry()::register);
         }
@@ -564,7 +574,7 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
             }
         }
 
-        targetConfiguration.setEnvironment(new Environment(this.environment,
+        targetConfiguration.setEnvironment(new Environment(MybatisSqlSessionFactoryBean.class.getSimpleName(),
             this.transactionFactory == null ? new SpringManagedTransactionFactory() : this.transactionFactory,
             this.dataSource));
 
@@ -592,7 +602,7 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
             LOGGER.debug(() -> "Property 'mapperLocations' was not specified.");
         }
 
-        SqlSessionFactory sqlSessionFactory = new MybatisSqlSessionFactoryBuilder().build(targetConfiguration);
+        final SqlSessionFactory sqlSessionFactory = new MybatisSqlSessionFactoryBuilder().build(targetConfiguration);
 
         // TODO SqlRunner
         SqlHelper.FACTORY = sqlSessionFactory;

+ 0 - 121
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/toolkit/PackageHelper.java

@@ -1,121 +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.extension.toolkit;
-
-import java.io.File;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.core.io.support.ResourcePatternResolver;
-import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
-import org.springframework.core.type.classreading.MetadataReader;
-import org.springframework.core.type.classreading.MetadataReaderFactory;
-import org.springframework.util.ClassUtils;
-
-import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
-
-/**
- * 包扫描辅助类
- *
- * @author hubin
- * @since 2016-06-16
- */
-public class PackageHelper {
-
-    /**
-     * 别名通配符设置
-     * <p>
-     * &lt;property name="typeAliasesPackage" value="com.baomidou.*.entity"/&gt;
-     * </p>
-     *
-     * @param typeAliasesPackage 类别名包路径
-     * @return
-     */
-    public static String[] convertTypeAliasesPackage(String typeAliasesPackage) {
-        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
-        MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
-        String pkg = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
-            + ClassUtils.convertClassNameToResourcePath(typeAliasesPackage) + "/*.class";
-        /*
-         * 将加载多个绝对匹配的所有Resource
-         * 将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分,然后进行遍历模式匹配,排除重复包路径
-         */
-        try {
-            Set<String> set = new HashSet<>();
-            Resource[] resources = resolver.getResources(pkg);
-            if (resources != null && resources.length > 0) {
-                MetadataReader metadataReader;
-                for (Resource resource : resources) {
-                    if (resource.isReadable()) {
-                        metadataReader = metadataReaderFactory.getMetadataReader(resource);
-                        set.add(ClassUtils.getPackageName(metadataReader.getClassMetadata().getClassName()));
-                    }
-                }
-            }
-            if (!set.isEmpty()) {
-                return set.toArray(new String[]{});
-            }
-            return new String[0];
-        } catch (Exception e) {
-            throw ExceptionUtils.mpe("not find typeAliasesPackage: %s", e, pkg);
-        }
-    }
-
-
-    /**
-     * 扫描获取指定包路径所有类
-     *
-     * @param typePackage 扫描类包路径
-     * @return ignore
-     */
-    public static Set<Class<?>> scanTypePackage(String typePackage) {
-        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
-        MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
-        String pkg = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
-            + ClassUtils.convertClassNameToResourcePath(typePackage) + "/*.class";
-        /*
-         * 将加载多个绝对匹配的所有Resource
-         * 将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分,然后进行遍历模式匹配,排除重复包路径
-         */
-        try {
-            Set<Class<?>> set = new HashSet<>();
-            Resource[] resources = resolver.getResources(pkg);
-            if (resources != null && resources.length > 0) {
-                MetadataReader metadataReader;
-                for (Resource resource : resources) {
-                    if (resource.isReadable()) {
-                        metadataReader = metadataReaderFactory.getMetadataReader(resource);
-                        set.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
-                    }
-                }
-            }
-            return set;
-        } catch (Exception e) {
-            throw ExceptionUtils.mpe("not find scanTypePackage: %s", e, pkg);
-        }
-    }
-
-    /**
-     * 新建文件目录
-     *
-     * @param file 文件
-     */
-    public static void mkDir(File file) {
-        file.mkdirs();
-    }
-}

+ 3 - 4
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/IFileCreate.java

@@ -16,12 +16,11 @@
 package com.baomidou.mybatisplus.generator.config;
 
 
-import java.io.File;
-
-import com.baomidou.mybatisplus.extension.toolkit.PackageHelper;
 import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
 import com.baomidou.mybatisplus.generator.config.rules.FileType;
 
+import java.io.File;
+
 /**
  * 文件覆盖接口
  *
@@ -49,7 +48,7 @@ public interface IFileCreate {
         File file = new File(filePath);
         boolean exist = file.exists();
         if (!exist) {
-            PackageHelper.mkDir(file.getParentFile());
+            file.getParentFile().mkdir();
         }
     }
 }

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

@@ -15,18 +15,9 @@
  */
 package com.baomidou.mybatisplus.generator.engine;
 
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 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.extension.toolkit.PackageHelper;
 import com.baomidou.mybatisplus.generator.InjectionConfig;
 import com.baomidou.mybatisplus.generator.config.ConstVal;
 import com.baomidou.mybatisplus.generator.config.FileOutConfig;
@@ -35,6 +26,13 @@ import com.baomidou.mybatisplus.generator.config.TemplateConfig;
 import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
 import com.baomidou.mybatisplus.generator.config.po.TableInfo;
 import com.baomidou.mybatisplus.generator.config.rules.FileType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 
 /**
@@ -274,7 +272,7 @@ public abstract class AbstractTemplateEngine {
         File file = new File(filePath);
         boolean exist = file.exists();
         if (!exist) {
-            PackageHelper.mkDir(file.getParentFile());
+            file.getParentFile().mkdirs();
         }
         return !exist || getConfigBuilder().getGlobalConfig().isFileOverride();
     }