Skip to content

fix: 在复制countBoundSql的时候,复制additionalParameter #837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading