Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
youapple opened this issue Sep 6, 2017 · 18 comments

Comments

@youapple
Copy link

youapple commented Sep 6, 2017

No description provided.

@abel533
Copy link
Collaborator

abel533 commented Sep 6, 2017

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

@duweili
Copy link

duweili commented Dec 19, 2017

image

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

@abel533
Copy link
Collaborator

abel533 commented Dec 21, 2017

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

@duxiaolong
Copy link

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

@duxiaolong
Copy link

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

@hanzhenchaoGit
Copy link

@duweili 我也是这个问题 同问

@hanzhenchaoGit
Copy link

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

@huzhixiang
Copy link

怎么解决呢?加了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
Copy link
Collaborator

abel533 commented Mar 29, 2018

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

@macrowangy
Copy link

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

@abel533
Copy link
Collaborator

abel533 commented Jun 25, 2018

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

@ghost
Copy link

ghost commented Jul 24, 2018

遇到同样的问题,各种配置无果后,发现代码寄几写的有问题。是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
Copy link
Collaborator

abel533 commented Jul 28, 2018

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

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

@abel533 abel533 closed this as completed Jul 28, 2018
@logicjwell
Copy link

logicjwell commented Jan 7, 2019

在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
Copy link

哈哈哈......

@smfx1314
Copy link

smfx1314 commented May 7, 2019

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

@slyang520
Copy link

怎么解 我也遇到了

@SanJingYe88
Copy link

在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");

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests