浏览代码

3.5.2.2-SNAPSHOT fix: InterceptorIgnore 不能过滤 selectKey 的问题

miemie 3 年之前
父节点
当前提交
9656f4b271

+ 3 - 3
build.gradle

@@ -2,7 +2,7 @@ import java.time.LocalDateTime
 
 
 allprojects {
 allprojects {
     group = 'com.baomidou'
     group = 'com.baomidou'
-    version = "3.5.2.1-SNAPSHOT"
+    version = "3.5.2.2-SNAPSHOT"
 }
 }
 
 
 ext {
 ext {
@@ -16,7 +16,7 @@ ext {
         mybatisSpringBootStarterVersion = '2.2.2',
         mybatisSpringBootStarterVersion = '2.2.2',
         springVersion = '5.3.15',
         springVersion = '5.3.15',
         springBootVersion = '2.5.3',
         springBootVersion = '2.5.3',
-        jsqlparserVersion = '4.5',
+        jsqlparserVersion = '4.4', // 4.5 有bug
         junitVersion = '5.9.0',
         junitVersion = '5.9.0',
     ]
     ]
 
 
@@ -127,7 +127,7 @@ subprojects {
                 attributes 'Built-By': System.getProperty("user.name")
                 attributes 'Built-By': System.getProperty("user.name")
                 attributes 'Build-Jdk': System.getProperty("java.version")
                 attributes 'Build-Jdk': System.getProperty("java.version")
                 attributes 'Build-Timestamp': LocalDateTime.now().format("yyyy-MM-dd HH:mm:ss")
                 attributes 'Build-Timestamp': LocalDateTime.now().format("yyyy-MM-dd HH:mm:ss")
-                attributes 'Automatic-Module-Name': "${project.group}.${project.name.replaceAll("-",".")}"
+                attributes 'Automatic-Module-Name': "${project.group}.${project.name.replaceAll("-", ".")}"
             }
             }
         }
         }
     }
     }

+ 1 - 0
changelog-temp.md

@@ -1 +1,2 @@
 - 多租户插件:多表join表名必需起别名,否则追加的过滤条件不带前缀
 - 多租户插件:多表join表名必需起别名,否则追加的过滤条件不带前缀
+- fix: InterceptorIgnore 不能过滤 selectKey 的问题

+ 0 - 5
mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/InterceptorIgnore.java

@@ -63,11 +63,6 @@ public @interface InterceptorIgnore {
      */
      */
     String dataPermission() default "1";
     String dataPermission() default "1";
 
 
-    /**
-     * 分表 {@link com.baomidou.mybatisplus.extension.plugins.inner.ShardingInnerInterceptor}
-     */
-    String sharding() default "";
-
     /**
     /**
      * 其他的
      * 其他的
      * <p>
      * <p>

+ 5 - 7
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/plugins/InterceptorIgnoreHelper.java

@@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.baomidou.mybatisplus.core.toolkit.*;
 import com.baomidou.mybatisplus.core.toolkit.*;
 import lombok.Builder;
 import lombok.Builder;
 import lombok.Data;
 import lombok.Data;
+import org.apache.ibatis.executor.keygen.SelectKeyGenerator;
 
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Method;
 import java.util.HashSet;
 import java.util.HashSet;
@@ -99,16 +100,16 @@ public abstract class InterceptorIgnoreHelper {
         return willIgnore(id, InterceptorIgnoreCache::getDataPermission);
         return willIgnore(id, InterceptorIgnoreCache::getDataPermission);
     }
     }
 
 
-    public static boolean willIgnoreSharding(String id) {
-        return willIgnore(id, InterceptorIgnoreCache::getSharding);
-    }
-
     public static boolean willIgnoreOthersByKey(String id, String key) {
     public static boolean willIgnoreOthersByKey(String id, String key) {
         return willIgnore(id, i -> CollectionUtils.isNotEmpty(i.getOthers()) && i.getOthers().getOrDefault(key, false));
         return willIgnore(id, i -> CollectionUtils.isNotEmpty(i.getOthers()) && i.getOthers().getOrDefault(key, false));
     }
     }
 
 
     public static boolean willIgnore(String id, Function<InterceptorIgnoreCache, Boolean> function) {
     public static boolean willIgnore(String id, Function<InterceptorIgnoreCache, Boolean> function) {
         InterceptorIgnoreCache cache = INTERCEPTOR_IGNORE_CACHE.get(id);
         InterceptorIgnoreCache cache = INTERCEPTOR_IGNORE_CACHE.get(id);
+        if (cache == null && id.endsWith(SelectKeyGenerator.SELECT_KEY_SUFFIX)) {
+            // 支持一下 selectKey
+            cache = INTERCEPTOR_IGNORE_CACHE.get(id.substring(0, id.length() - SelectKeyGenerator.SELECT_KEY_SUFFIX.length()));
+        }
         if (cache == null) {
         if (cache == null) {
             cache = INTERCEPTOR_IGNORE_CACHE.get(id.substring(0, id.lastIndexOf(StringPool.DOT)));
             cache = INTERCEPTOR_IGNORE_CACHE.get(id.substring(0, id.lastIndexOf(StringPool.DOT)));
         }
         }
@@ -126,7 +127,6 @@ public abstract class InterceptorIgnoreHelper {
             .blockAttack(chooseBoolean(mapper.getBlockAttack(), method.getBlockAttack()))
             .blockAttack(chooseBoolean(mapper.getBlockAttack(), method.getBlockAttack()))
             .illegalSql(chooseBoolean(mapper.getIllegalSql(), method.getIllegalSql()))
             .illegalSql(chooseBoolean(mapper.getIllegalSql(), method.getIllegalSql()))
             .dataPermission(chooseBoolean(mapper.getDataPermission(), method.getDataPermission()))
             .dataPermission(chooseBoolean(mapper.getDataPermission(), method.getDataPermission()))
-            .sharding(chooseBoolean(mapper.getSharding(), method.getSharding()))
             .others(chooseOthers(mapper.getOthers(), method.getOthers()))
             .others(chooseOthers(mapper.getOthers(), method.getOthers()))
             .build();
             .build();
     }
     }
@@ -138,7 +138,6 @@ public abstract class InterceptorIgnoreHelper {
             .blockAttack(getBoolean("blockAttack", name, ignore.blockAttack()))
             .blockAttack(getBoolean("blockAttack", name, ignore.blockAttack()))
             .illegalSql(getBoolean("illegalSql", name, ignore.illegalSql()))
             .illegalSql(getBoolean("illegalSql", name, ignore.illegalSql()))
             .dataPermission(getBoolean("dataPermission", name, ignore.dataPermission()))
             .dataPermission(getBoolean("dataPermission", name, ignore.dataPermission()))
-            .sharding(getBoolean("sharding", name, ignore.sharding()))
             .others(getOthers(name, ignore.others()))
             .others(getOthers(name, ignore.others()))
             .build();
             .build();
     }
     }
@@ -214,7 +213,6 @@ public abstract class InterceptorIgnoreHelper {
         private Boolean blockAttack;
         private Boolean blockAttack;
         private Boolean illegalSql;
         private Boolean illegalSql;
         private Boolean dataPermission;
         private Boolean dataPermission;
-        private Boolean sharding;
         private Map<String, Boolean> others;
         private Map<String, Boolean> others;
     }
     }
 }
 }

+ 6 - 8
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/DynamicTableNameInnerInterceptor.java

@@ -62,11 +62,9 @@ public class DynamicTableNameInnerInterceptor implements InnerInterceptor {
 
 
     @Override
     @Override
     public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
     public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
+        if (InterceptorIgnoreHelper.willIgnoreDynamicTableName(ms.getId())) return;
         PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql);
         PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql);
-        if (!InterceptorIgnoreHelper.willIgnoreDynamicTableName(ms.getId())) {
-            // 非忽略执行
-            mpBs.sql(this.changeTable(mpBs.sql()));
-        }
+        mpBs.sql(this.changeTable(mpBs.sql()));
     }
     }
 
 
     @Override
     @Override
@@ -75,11 +73,11 @@ public class DynamicTableNameInnerInterceptor implements InnerInterceptor {
         MappedStatement ms = mpSh.mappedStatement();
         MappedStatement ms = mpSh.mappedStatement();
         SqlCommandType sct = ms.getSqlCommandType();
         SqlCommandType sct = ms.getSqlCommandType();
         if (sct == SqlCommandType.INSERT || sct == SqlCommandType.UPDATE || sct == SqlCommandType.DELETE) {
         if (sct == SqlCommandType.INSERT || sct == SqlCommandType.UPDATE || sct == SqlCommandType.DELETE) {
-            if (!InterceptorIgnoreHelper.willIgnoreDynamicTableName(ms.getId())) {
-                // 非忽略执行
-                PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
-                mpBs.sql(this.changeTable(mpBs.sql()));
+            if (InterceptorIgnoreHelper.willIgnoreDynamicTableName(ms.getId())) {
+                return;
             }
             }
+            PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
+            mpBs.sql(this.changeTable(mpBs.sql()));
         }
         }
     }
     }
 
 

+ 1 - 1
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/TenantLineInnerInterceptor.java

@@ -135,7 +135,7 @@ public class TenantLineInnerInterceptor extends JsqlParserSupport implements Inn
 
 
         Select select = insert.getSelect();
         Select select = insert.getSelect();
         if (select != null) {
         if (select != null) {
-            this.processInsertSelect(select.getSelectBody());
+            processInsertSelect(select.getSelectBody());
         } else if (insert.getItemsList() != null) {
         } else if (insert.getItemsList() != null) {
             // fixed github pull/295
             // fixed github pull/295
             ItemsList itemsList = insert.getItemsList();
             ItemsList itemsList = insert.getItemsList();