From fc3f568be148d7b75c5ef934e44969c27898b79d Mon Sep 17 00:00:00 2001 From: yanglin Date: Thu, 9 Jan 2025 17:44:08 +0800 Subject: [PATCH] =?UTF-8?q?REQ-3502:=20fix=E5=8F=8D=E5=B0=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/BeautifulPaginationInterceptor.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/mybatis/BeautifulPaginationInterceptor.java b/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/mybatis/BeautifulPaginationInterceptor.java index 3f7c9999..8f1f8677 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/mybatis/BeautifulPaginationInterceptor.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/mybatis/BeautifulPaginationInterceptor.java @@ -18,6 +18,7 @@ import org.apache.ibatis.plugin.Interceptor; import org.apache.ibatis.plugin.Intercepts; import org.apache.ibatis.plugin.Invocation; import org.apache.ibatis.plugin.Signature; +import org.apache.ibatis.reflection.DefaultReflectorFactory; import org.apache.ibatis.reflection.MetaObject; import org.apache.ibatis.reflection.SystemMetaObject; import org.springframework.core.Ordered; @@ -36,12 +37,13 @@ import java.util.concurrent.atomic.AtomicBoolean; args = {Connection.class, Integer.class})}) public class BeautifulPaginationInterceptor implements Interceptor, Ordered { + private static final DefaultReflectorFactory REFLECTOR_FACTORY = new DefaultReflectorFactory(); private final PaginationInterceptor delegate = new CustomPaginationInterceptor(); @Override public Object intercept(Invocation invocation) throws Throwable { StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget()); - MetaObject metaObject = SystemMetaObject.forObject(statementHandler); + MetaObject metaObject = systemMetaForObject(statementHandler); MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement"); if (SqlCommandType.SELECT != mappedStatement.getSqlCommandType() || StatementType.CALLABLE == mappedStatement.getStatementType()) { @@ -70,7 +72,7 @@ public class BeautifulPaginationInterceptor implements Interceptor, Ordered { private static String tryBuildSql(Invocation invocation) { Connection connection = (Connection) (invocation.getArgs()[0]); StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget()); - MetaObject metaObject = SystemMetaObject.forObject(statementHandler); + MetaObject metaObject = systemMetaForObject(statementHandler); MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement"); BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql"); try (PreparedStatement statement = connection.prepareStatement(boundSql.getSql())) { @@ -86,6 +88,13 @@ public class BeautifulPaginationInterceptor implements Interceptor, Ordered { } } + public static MetaObject systemMetaForObject(Object object) { + return MetaObject.forObject(object, + SystemMetaObject.DEFAULT_OBJECT_FACTORY, + SystemMetaObject.DEFAULT_OBJECT_WRAPPER_FACTORY, + REFLECTOR_FACTORY); + } + private static class CustomPaginationInterceptor extends PaginationInterceptor { public CustomPaginationInterceptor() {