Update PageInterceptor.java
// 没想到缓存作用这么大,我用的之后直接超时。 // 因为没有命中缓存,fix private Long count(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { String countMsId = ms.getId() ; // fix: 手写sql对应_COUNT 保持不变 // fix: selectByExamle对应selectCountByExample if (countMsId.endsWith("selectByExample")){ countMsId = ms.getId().replaceAll("selectByExample$", "selectCountByExample"); }else{ countMsId = ms.getId() + countSuffix; } Long count; // 先判断是否存在手写的 count 查询 MappedStatement countMs = ExecutorUtil.getExistedMappedStatement(ms.getConfiguration(), countMsId); if (countMs != null) { count = ExecutorUtil.executeManualCount(executor, countMs, parameter, boundSql, resultHandler); } else { if (msCountMap != null) { countMs = msCountMap.get(countMsId); } // 自动创建 if (countMs == null) { // 根据当前的 ms 创建一个返回值为 Long 类型的 ms countMs = MSUtils.newCountMappedStatement(ms, countMsId); if (msCountMap != null) { msCountMap.put(countMsId, countMs); } } count = ExecutorUtil.executeAutoCount(this.dialect, executor, countMs, parameter, boundSql, rowBounds, resultHandler); } return count; }
mb开没看见pull 请求,也不知道, 改不改也不给个回复。就不该搭理ta这玩意。@Rui
即将发布的新版本增加了参数:
-
countMsIdGen(5.3.2+):count 方法的 msId 生成方式,默认是 查询的 msId + countSuffix,想要自己定义时,可以实现com.github.pagehelper.CountMsIdGen接口,将该参数配置为实现的全限定类名即可。 一个常见的用途: 在有Example查询的情况,selectByExample可以使用对应的selectCountByExample方法进行 count 查询。