当前使用版本(必填,否则不予处理)
3.5.1
IPage 增加一个判断属性,nextPage = false 可以根据业务
该问题是如何引起的?(确定最新版也有问题再提!!!)
在分页接口类增加下面的方法
/
* 分页 Page 对象接口
*
* @author hubin
* @since 2018-06-09
*/
public interface IPage
/**
* 通过 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
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
// 处理 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 查询即可,拉去下一页没有拉取到即为结束