Browse Source

Merge branch '3.0' into 3.gay

miemie 3 years ago
parent
commit
16a549cec0

+ 4 - 3
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/LambdaUtils.java

@@ -60,10 +60,11 @@ public final class LambdaUtils {
             throw new MybatisPlusException(message);
         } catch (InvocationTargetException | IllegalAccessException e) {
             throw new MybatisPlusException(e);
-        } catch (RuntimeException e) {
-            // JDK 16 模块化后不能访问 java.lang.invoke.SerializedLambda 了,走序列化路线
+        } catch (Error e) {
+            // JDK 16 模块化后不能使用反射访问其他模块的字段,因此这里需要使用序列化的方式进行处理
             // https://gitee.com/baomidou/mybatis-plus/issues/I3XDT9
-            if (e.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
+            Throwable cause = e.getCause();
+            if (cause != null && cause.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
                 return new ShadowLambdaMeta(com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda.extract(func));
             }
             throw e;

+ 5 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/PaginationInnerInterceptor.java

@@ -268,6 +268,11 @@ public class PaginationInnerInterceptor implements InnerInterceptor {
         }
         try {
             Select select = (Select) CCJSqlParserUtil.parse(sql);
+            SelectBody selectBody = select.getSelectBody();
+            // https://github.com/baomidou/mybatis-plus/issues/3920  分页增加union语法支持
+            if(selectBody instanceof SetOperationList) {
+                return lowLevelCountSql(sql);
+            }
             PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
             Distinct distinct = plainSelect.getDistinct();
             GroupByElement groupBy = plainSelect.getGroupBy();