ソースを参照

发布3.0.7.2-SNAPSHOT.

nieqiurong 6 年 前
コミット
9915d84b86

+ 1 - 1
build.gradle

@@ -71,7 +71,7 @@ ext {
 
 allprojects {
     group = 'com.baomidou'
-    version = '3.0.7.1-SNAPSHOT'
+    version = '3.0.7.2-SNAPSHOT'
 }
 
 description = "Mybatis 增强工具包 - 只做增强不做改变,简化CRUD操作"

+ 12 - 4
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisConfiguration.java

@@ -16,6 +16,7 @@
 package com.baomidou.mybatisplus.core;
 
 import com.baomidou.mybatisplus.core.config.GlobalConfig;
+import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import org.apache.ibatis.binding.MapperRegistry;
 import org.apache.ibatis.logging.Log;
@@ -84,12 +85,19 @@ public class MybatisConfiguration extends Configuration {
     @Override
     public void addMappedStatement(MappedStatement ms) {
         logger.debug("addMappedStatement: " + ms.getId());
-        if (mappedStatements.containsKey(ms.getId())) {
+        if (GlobalConfigUtils.isRefresh(ms.getConfiguration())) {
             /*
-             * 说明已加载了xml中的节点; 忽略mapper中的SqlProvider数据
+             * 支持是否自动刷新 XML 变更内容,开发环境使用【 注:生产环境勿用!】
              */
-            logger.error("mapper[" + ms.getId() + "] is ignored, because it exists, maybe from xml file");
-            return;
+            mappedStatements.remove(ms.getId());
+        } else {
+            if (mappedStatements.containsKey(ms.getId())) {
+                /*
+                 * 说明已加载了xml中的节点; 忽略mapper中的SqlProvider数据
+                 */
+                logger.error("mapper[" + ms.getId() + "] is ignored, because it exists, maybe from xml file");
+                return;
+            }
         }
         super.addMappedStatement(ms);
     }

+ 4 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/config/GlobalConfig.java

@@ -52,6 +52,10 @@ public class GlobalConfig implements Serializable {
      * 是否开启 LOGO
      */
     private boolean banner = true;
+    /**
+     * 是否刷新 mapper
+     */
+    private boolean refresh = false;
     /**
      * 缓存 Sql 解析初始化
      */

+ 5 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/GlobalConfigUtils.java

@@ -160,6 +160,11 @@ public class GlobalConfigUtils {
         return getGlobalConfig(configuration).getSuperMapperClass();
     }
 
+    public static boolean isRefresh(Configuration configuration) {
+        return getGlobalConfig(configuration).isRefresh();
+    }
+
+
     public static Set<String> getMapperRegistryCache(Configuration configuration) {
         return getGlobalConfig(configuration).getMapperRegistryCache();
     }

+ 5 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/spring/MybatisSqlSessionFactoryBean.java

@@ -623,6 +623,11 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
         globalConfig.signGlobalConfig(sqlSessionFactory);
 
         if (!isEmpty(this.mapperLocations)) {
+            if (globalConfig.isRefresh()) {
+                //TODO 设置自动刷新配置 减少配置
+                new MybatisMapperRefresh(this.mapperLocations, sqlSessionFactory, 2,
+                    2, true);
+            }
             for (Resource mapperLocation : this.mapperLocations) {
                 if (mapperLocation == null) {
                     continue;