Mybatis-PageHelper icon indicating copy to clipboard operation
Mybatis-PageHelper copied to clipboard

Update PageInterceptor.java

Open forzjing opened this issue 3 years ago • 1 comments

// 没想到缓存作用这么大,我用的之后直接超时。 // 因为没有命中缓存,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; }

forzjing avatar Jul 21 '22 10:07 forzjing

mb开没看见pull 请求,也不知道, 改不改也不给个回复。就不该搭理ta这玩意。@Rui

forzjing avatar Aug 04 '22 09:08 forzjing

即将发布的新版本增加了参数:

  1. countMsIdGen(5.3.2+):count 方法的 msId 生成方式,默认是 查询的 msId + countSuffix,想要自己定义时,可以实现 com.github.pagehelper.CountMsIdGen 接口,将该参数配置为实现的全限定类名即可。 一个常见的用途: 在有Example查询的情况,selectByExample 可以使用对应的 selectCountByExample 方法进行 count 查询。

abel533 avatar Sep 18 '22 07:09 abel533