pagehelper / pagehelper-spring-boot

pagehelper-spring-boot
MIT License
1.54k stars 311 forks source link

pageInfo的total属性是当前页记录数,如何配置使total设置成总记录数 #21

Closed youapple closed 6 years ago

abel533 commented 7 years ago

total 是总记录数,不是当前页。

duweili commented 6 years ago

image

SELECT count(0) FROM T 值为3,但是结果中的total显示的是我的当前分页的记录数,这个要怎样设置?谢谢大神!

abel533 commented 6 years ago

@duweili SQL日志有没有检查过?确定经过分页了吗?

duxiaolong commented 6 years ago

@duweili 这个问题解决了吗?我这里也是这个问题,检查打印的sql,确认分页了。但是total是当前页的记录数。

duxiaolong commented 6 years ago

@abel533 配置文件配置方言就好了。 pagehelper.dialect=com.github.pagehelper.dialect.helper.OracleDialect 但是,配置方言以后,列表就没有分页了。

hanzhenchaoGit commented 6 years ago

@duweili 我也是这个问题 同问

hanzhenchaoGit commented 6 years ago

@duxiaolong 用了dubbo了是吗 我这个问题解决了 分页没有问题了

huzhixiang commented 6 years ago

怎么解决呢?加了dialect: com.github.pagehelper.dialect.helper.MySqlDialect,就不分页了 { "code": 1, "msg": "成功", "data": { "pageNum": 1, "pageSize": 18, "size": 18, "startRow": 0, "endRow": 17, "total": 18, "pages": 1,

abel533 commented 6 years ago

@huzhixiang 不应该配置 dialect,应该是 helperDialect,文档有说明。

macrowangy commented 6 years ago

无论怎么修改配置,查询总是全部数据,拦截不生效(springboot的使用)

abel533 commented 6 years ago

@githupwangyu 看日志SQL对不对。。spring boot情况下,只需要引入Starter就能用。

ghost commented 6 years ago

遇到同样的问题,各种配置无果后,发现代码寄几写的有问题。是PageInfo构造参数传了List实例的原因,一定要传Page实例

解决方案: Page page = PageHelper.startPage(xx,xx); // todo:your query PageInfo pageInfo = new PageInfo<>(page); !!!重点这里:page 参数一定要传Page的实例,才会得到正确的total,传List的实例会调用size();

查看了源码才知道: public PageSerializable(List list) { this.list = list; if(list instanceof Page){ this.total = ((Page)list).getTotal(); } else { this.total = list.size(); //!!!如果传List的实例,这里调用的了size } }

abel533 commented 6 years ago

@GithubXie40 不是你说的这样,通过分页插件处理后的结果,表面上是 List 类型,实际是 Page( extends ArrayList)。只有不是经过分页,或者你自己对结果处理后再用 PageInfo,才没有 total。

注意 java8 lambda 处理后的流会丢失分页信息。

logicjwell commented 5 years ago

在lambda之前,先搞一个pageinfo, lambda之后,把分页信息copy进去 @

` List requirementObjs= requirement.getRequirements(currentPage,pageSize); PageInfo origPageInfo = new PageInfo<>(requirementObjs);

    List<BaseRequirementResp> baseRequirementResps = requirementObjs.stream().map(o-> new BaseRequirementResp(o)).collect(Collectors.toList());

    PageInfo<BaseRequirementResp> pageInfo = new PageInfo<>(baseRequirementResps);
    BeanUtils.copyProperties(origPageInfo,pageInfo,"list");

`

zxksunflower commented 5 years ago

哈哈哈......

smfx1314 commented 5 years ago

我的也是total总是等于pageSize,如果使用lamada的话,数据确实会丢失

slyang520 commented 4 years ago

怎么解 我也遇到了

SanJingYe88 commented 4 years ago

在lambda之前,先搞一个pageinfo, lambda之后,把分页信息copy进去 @

` List requirementObjs= requirement.getRequirements(currentPage,pageSize); PageInfo origPageInfo = new PageInfo<>(requirementObjs);

    List<BaseRequirementResp> baseRequirementResps = requirementObjs.stream().map(o-> new BaseRequirementResp(o)).collect(Collectors.toList());

    PageInfo<BaseRequirementResp> pageInfo = new PageInfo<>(baseRequirementResps);
    BeanUtils.copyProperties(origPageInfo,pageInfo,"list");

` 这样可以用, 结果没问题