当前使用版本(必填,否则不予处理)

3.5.1

IPage 增加一个判断属性,nextPage = false 可以根据业务

该问题是如何引起的?(确定最新版也有问题再提!!!)

在分页接口类增加下面的方法 / * 分页 Page 对象接口 * * @author hubin * @since 2018-06-09 */ public interface IPage extends Serializable / * 通过 nextPage 查询 【 默认: false】 false 为 limit = getSize();true为 limit = getSize() + 1 , * @return / default boolean getNextPage () { return false; } / * 获取每页显示条数+1, 用于limit中, * 当 getNextPage() 为true 使用,通过多查一次记录来判断是否有下一页的逻辑实现 * * @return 每页显示条数 / default long getNextSize(){ return getSize() + 1; }

/**
 * 通过 nextPage 查询 【 默认: false】 false 为 limit = getSize();true为 limit = getSize() + 1 ,
 * 如果 nextPage() 为true时,执行 执行isNextPage 来判断是否有下一次,并删除多查的一条数据记录
 * @return
 */
default boolean isNextPage(){
    List<T> list = this.getRecords();
    long size  = getSize();
    if(null != list && list.size() > 1 && list.size() > size ){
        list.remove((int) size);
        return true;
    }
    return false;
}

}

/ * 简单分页模型 * * @author hubin * @since 2018-06-09 */ public class Page implements IPage / * 满足移动端,是否有下页的逻辑,通过多查一条的逻辑,来解决是否有下页 */ // @Setter protected boolean nextPage = false;

public void setNextPage(boolean nextPage) {
    this.nextPage = nextPage;
}

@Override
public boolean getNextPage() {
    return this.nextPage;
}
/**
 * 是否存在下一页
 *
 * @return true / false
 */
public boolean hasNext() {
    if (getNextPage()){
        return isNextPage();
    }
    return this.current < this.getPages();
}

} /* * 分页拦截器 *

* 默认对 left join 进行优化,虽然能优化count,但是加上分页的话如果1对多本身结果条数就是不正确的 * * @author hubin * @since 3.4.0 / @Data @NoArgsConstructor @SuppressWarnings({"rawtypes"}) public class PaginationInnerInterceptor implements InnerInterceptor { @Override public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { IPage<?> page = (IPage<?>) ParameterUtils.findPage(parameter).orElse(null); if (null == page) { return; }

    // 处理 orderBy 拼接
    boolean addOrdered = false;
    String buildSql = boundSql.getSql();
    List<OrderItem> orders = page.orders();
    if (CollectionUtils.isNotEmpty(orders)) {
        addOrdered = true;
        buildSql = this.concatOrderBy(buildSql, orders);
    }

    // size 小于 0 且不限制返回值则不构造分页sql
    Long _limit = page.maxLimit() != null ? page.maxLimit() : maxLimit;
    if (page.getSize() < 0 && null == _limit) {
        if (addOrdered) {
            PluginUtils.mpBoundSql(boundSql).sql(buildSql);
        }
        return;
    }

    handlerLimit(page, _limit);
    IDialect dialect = findIDialect(executor);

    final Configuration configuration = ms.getConfiguration();
    // ===============变更前====================
    //DialectModel model = dialect.buildPaginationSql(buildSql, page.offset(), page.getSize());
    // ===============变更后为====================
    long size = page.nextPage() ? page.getNextSize() : page.getSize();
    DialectModel model = dialect.buildPaginationSql(buildSql, page.offset(), size);
    // ===============变更后为====================

    PluginUtils.MPBoundSql mpBoundSql = PluginUtils.mpBoundSql(boundSql);

    List<ParameterMapping> mappings = mpBoundSql.parameterMappings();
    Map<String, Object> additionalParameter = mpBoundSql.additionalParameters();
    model.consumers(mappings, configuration, additionalParameter);
    mpBoundSql.sql(model.getDialectSql());
    mpBoundSql.parameterMappings(mappings);
}

}

Comment From: suvenw

// ===============变更后为==================== long size = page.getNextPage() ? page.getNextSize() : page.getSize(); DialectModel model = dialect.buildPaginationSql(buildSql, page.offset(), size); // ===============变更后为====================

Comment From: qmdx

如果是移动端,你只需要关闭 count 查询即可,拉去下一页没有拉取到即为结束