Skip to content

Commit

Permalink
fix: 在复制countBoundSql的时候,复制additionalParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhi-jiang committed Sep 2, 2024
1 parent b678308 commit 51ed307
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/github/pagehelper/PageInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Future;

Expand Down Expand Up @@ -183,6 +184,12 @@ private Future<Long> asyncCount(MappedStatement ms, BoundSql boundSql, Object pa
Configuration configuration = ms.getConfiguration();
//异步不能复用 BoundSql,因为分页使用时会添加分页参数,这里需要复制一个新的
BoundSql countBoundSql = new BoundSql(configuration, boundSql.getSql(), new ArrayList<>(boundSql.getParameterMappings()), parameter);
Map<String, Object> additionalParameter = ExecutorUtil.getAdditionalParameter(boundSql);
if (additionalParameter != null){
for (String key : additionalParameter.keySet()) {
countBoundSql.setAdditionalParameter(key, additionalParameter.get(key));
}
}
//异步想要起作用需要新的数据库连接,需要独立的事务,创建新的Executor,因此异步查询只适合在独立查询中使用,如果混合增删改操作,不能开启异步
Environment environment = configuration.getEnvironment();
TransactionFactory transactionFactory = null;
Expand Down

0 comments on commit 51ed307

Please sign in to comment.