Kaynağa Gözat

fixed ILY8C 生成器指定 IdType 场景导入包

hubin 7 yıl önce
ebeveyn
işleme
657d518980

+ 10 - 13
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisSessionFactoryBuilder.java

@@ -15,6 +15,7 @@
  */
 package com.baomidou.mybatisplus.core;
 
+import java.io.Closeable;
 import java.io.InputStream;
 import java.io.Reader;
 import java.util.Properties;
@@ -42,33 +43,29 @@ public class MybatisSessionFactoryBuilder extends SqlSessionFactoryBuilder {
 
     @Override
     public SqlSessionFactory build(Reader reader, String environment, Properties properties) {
-        try {
-            MybatisXMLConfigBuilder parser = new MybatisXMLConfigBuilder(reader, environment, properties);
-            GlobalConfigUtils.setGlobalConfig(parser.getConfiguration(), this.globalConfig);
-            return build(parser.parse());
-        } catch (Exception e) {
-            throw ExceptionFactory.wrapException("Error building SqlSession.", e);
-        } finally {
-            ErrorContext.instance().reset();
-            IOUtils.closeQuietly(reader);
-        }
+        return build(new MybatisXMLConfigBuilder(reader, environment, properties), reader);
     }
 
     @Override
     public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) {
+        return build(new MybatisXMLConfigBuilder(inputStream, environment, properties), inputStream);
+    }
+
+    protected SqlSessionFactory build(MybatisXMLConfigBuilder parser, Closeable closeable) {
         try {
-            MybatisXMLConfigBuilder parser = new MybatisXMLConfigBuilder(inputStream, environment, properties);
             GlobalConfigUtils.setGlobalConfig(parser.getConfiguration(), this.globalConfig);
             return build(parser.parse());
         } catch (Exception e) {
             throw ExceptionFactory.wrapException("Error building SqlSession.", e);
         } finally {
             ErrorContext.instance().reset();
-            IOUtils.closeQuietly(inputStream);
+            IOUtils.closeQuietly(closeable);
         }
     }
 
-    // TODO 注入全局配置
+    /**
+     * 注入全局配置
+     */
     public void setGlobalConfig(GlobalConfig globalConfig) {
         this.globalConfig = globalConfig;
     }

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

@@ -395,6 +395,10 @@ public class ConfigBuilder {
             // 无父类开启 AR 模式
             tableInfo.getImportPackages().add(com.baomidou.mybatisplus.extension.activerecord.Model.class.getCanonicalName());
         }
+        if (null != globalConfig.getIdType()) {
+            // 指定需要 IdType 场景
+            tableInfo.getImportPackages().add(com.baomidou.mybatisplus.annotation.IdType.class.getCanonicalName());
+        }
         if (StringUtils.isNotEmpty(strategyConfig.getVersionFieldName())) {
             tableInfo.getFields().forEach(f -> {
                 if (strategyConfig.getVersionFieldName().equals(f.getName())) {