Skip to content

Commit f47692c

Browse files
committed
增加校验:在系统中发现了多个分页插件,请检查系统配置!
1 parent 30405b7 commit f47692c

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/main/java/com/github/pagehelper/PageHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.github.pagehelper.page.PageAutoDialect;
2929
import com.github.pagehelper.page.PageMethod;
3030
import com.github.pagehelper.page.PageParams;
31+
import com.github.pagehelper.util.MSUtils;
3132
import org.apache.ibatis.cache.CacheKey;
3233
import org.apache.ibatis.mapping.BoundSql;
3334
import org.apache.ibatis.mapping.MappedStatement;
@@ -49,6 +50,9 @@ public class PageHelper extends PageMethod implements Dialect {
4950

5051
@Override
5152
public boolean skip(MappedStatement ms, Object parameterObject, RowBounds rowBounds) {
53+
if(ms.getId().endsWith(MSUtils.COUNT)){
54+
throw new RuntimeException("在系统中发现了多个分页插件,请检查系统配置!");
55+
}
5256
Page page = pageParams.getPage(parameterObject, rowBounds);
5357
if (page == null) {
5458
return true;

src/main/java/com/github/pagehelper/PageInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Object intercept(Invocation invocation) throws Throwable {
9393
if (dialect.beforeCount(ms, parameter, rowBounds)) {
9494
//创建 count 查询的缓存 key
9595
CacheKey countKey = executor.createCacheKey(ms, parameter, RowBounds.DEFAULT, boundSql);
96-
countKey.update("_Count");
96+
countKey.update(MSUtils.COUNT);
9797
MappedStatement countMs = msCountMap.get(countKey);
9898
if (countMs == null) {
9999
//根据当前的 ms 创建一个返回值为 Long 类型的 ms

src/main/java/com/github/pagehelper/util/MSUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* @author liuzh
3838
*/
3939
public class MSUtils {
40+
public static final String COUNT = "_COUNT";
4041
private static final List<ResultMapping> EMPTY_RESULTMAPPING = new ArrayList<ResultMapping>(0);
4142

4243
/**
@@ -46,7 +47,7 @@ public class MSUtils {
4647
* @return
4748
*/
4849
public static MappedStatement newCountMappedStatement(MappedStatement ms) {
49-
MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId() + "_COUNT", ms.getSqlSource(), ms.getSqlCommandType());
50+
MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId() + COUNT, ms.getSqlSource(), ms.getSqlCommandType());
5051
builder.resource(ms.getResource());
5152
builder.fetchSize(ms.getFetchSize());
5253
builder.statementType(ms.getStatementType());

0 commit comments

Comments
 (0)