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 里的EMPTY属性和emptyPageInfo() 方法返回的对象不正确 #779

Closed
xiao8Git opened this issue Nov 6, 2023 · 1 comment

Comments

@xiao8Git
Copy link

xiao8Git commented Nov 6, 2023

测试代码

PageInfo<MemberCard> objectPageInfo = PageMethod.startPage(1, 10)
    .doSelectPageInfo(() -> baseMapper.getXxxx()
);

List<MemberCard> list = objectPageInfo.getList();
if (CollectionUtils.isEmpty(list)) {
    PageInfo empty = PageInfo.EMPTY;
    log.warn("hashCode:{}",empty.hashCode());
    List<MemberCard> pageList = empty.getList();
    pageList.add(new MemberCard());
    empty.setList(pageList);
    empty.setTotal(pageList.size());
    log.warn("Total:{}",empty.getTotal());
    return empty;
}

原 SQL

SELECT count(0) FROM member_card where 1=2

期望的结果:

PageInfo.EMPTY 永远返回空对象

日志内容

17:47:06.804 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - ==> Preparing: SELECT count(0) FROM member_card where 1=2
17:47:06.805 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - ==> Parameters:
17:47:06.811 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - <== Total: 1
17:47:06.812 WARN c.w.l.u.s.xxxxx - hashCode:1045255393
17:47:06.812 WARN c.w.l.u.s.xxxxx - Total:3
17:47:16.582 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - ==> Preparing: SELECT count(0) FROM member_card where 1=2
17:47:16.583 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - ==> Parameters:
17:47:16.589 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - <== Total: 1
17:47:16.590 WARN c.w.l.u.s.xxxxx - hashCode:1045255393
17:47:16.590 WARN c.w.l.u.s.xxxxx - Total:4
17:47:16.820 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - ==> Preparing: SELECT count(0) FROM member_card where 1=2
17:47:16.821 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - ==> Parameters:
17:47:16.827 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - <== Total: 1
17:47:16.827 WARN c.w.l.u.s.xxxxx - hashCode:1045255393
17:47:16.828 WARN c.w.l.u.s.xxxxx - Total:5
17:47:17.015 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - ==> Preparing: SELECT count(0) FROM member_card where 1=2
17:47:17.016 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - ==> Parameters:
17:47:17.022 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - <== Total: 1
17:47:17.024 WARN c.w.l.u.s.xxxxx - hashCode:1045255393
17:47:17.024 WARN c.w.l.u.s.xxxxx - Total:6
17:47:17.282 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - ==> Preparing: SELECT count(0) FROM member_card where 1=2
17:47:17.283 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - ==> Parameters:
17:47:17.290 DEBUG c.w.l.u.s.m.M.xxxXx_COUNT - <== Total: 1
17:47:17.292 WARN c.w.l.u.s.xxxxx - hashCode:1045255393
17:47:17.292 WARN c.w.l.u.s.xxxxx - Total:7

原因

PageInfo 类的EMPTY 属性是static final 只能赋值一次,全局只有一个,但暴露的方法可以被内部和外部修改,

public static final PageInfo EMPTY = new PageInfo(Collections.emptyList(), 0);
@abel533
Copy link
Collaborator

abel533 commented Nov 6, 2023

来个PR?

xiao8Git pushed a commit to xiao8Git/Mybatis-PageHelper that referenced this issue Nov 7, 2023
abel533 added a commit that referenced this issue Nov 9, 2023
@abel533 abel533 closed this as completed Nov 9, 2023
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

2 participants