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

数据查询返回后进行转化,hasNextPage属性值永远是false #810

Closed
1 task
zjfplayer opened this issue Apr 7, 2024 · 3 comments
Closed
1 task

Comments

@zjfplayer
Copy link

  • 我已在 issues 搜索类似问题,并且不存在相同的问题.

异常模板

使用环境

  • PageHelper 版本:1.4.7
  • 数据库类型和版本: oracle

SQL 解析错误

分页参数

Page page=PageHelper.startPage(1, 10);
List<UserInfo> list=userMapper.selectList();
List<UserDTO> dtoList=UserConverter.convertToDto(list);
PageInfo<UserDTO> pageInfo=new PageInfo(dtoList);
pageInfo.setTotal(page.getTotal());
pageInfo.setPages(page.getPages());
return pageInfo

原 SQL

select * from user_info limit 100;

期望的结果:

{
  "return_code": 0,
  "error_code": "",
  "error_message": "",
  "error_properties": {},
  "result": {
    "total":100,
    "list":[
    {
      "id":"23123",
      "account":"zhangsan",
      "name":"张三"
    },........
    ],
    "page_num":1,
    "page_size":10,
    "has_next_page":true
  }
}

完整异常信息

hasNextPage属性值异常

{
  "return_code": 0,
  "error_code": "",
  "error_message": "",
  "error_properties": {},
  "result": {
    "total":100,
    "list":[
    {
      "id":"23123",
      "account":"zhangsan",
      "name":"张三"
    }, ......],
    "page_num":1,
    "page_size":10,
    "has_next_page":false
  }
}

异常信息放在这里


### 其他类型的错误

## 功能建议

详细说明,尽可能提供(伪)代码示例。
@zjfplayer
Copy link
Author

是转化过后,所有属性都要手动赋值吗?

@abel533
Copy link
Collaborator

abel533 commented Apr 8, 2024

大概率是你转换方法丢失了分页信息,可以考虑用下面的方法:

/**
     * 数据对象转换
     *
     * @param function 用以转换数据对象的函数
     * @param <E>      目标类型
     * @return 转换了对象类型的包装结果
     */
    public <E> PageInfo<E> convert(Page.Function<T, E> function) {
        List<E> list = new ArrayList<E>(this.list.size());
        for (T t : this.list) {
            list.add(function.apply(t));
        }
        PageInfo<E> newPageInfo = new PageInfo<>(list);
        newPageInfo.setPageNum(this.pageNum);
        newPageInfo.setPageSize(this.pageSize);
        newPageInfo.setSize(this.size);
        newPageInfo.setStartRow(this.startRow);
        newPageInfo.setEndRow(this.endRow);
        newPageInfo.setTotal(this.total);
        newPageInfo.setPages(this.pages);
        newPageInfo.setPrePage(this.prePage);
        newPageInfo.setNextPage(this.nextPage);
        newPageInfo.setIsFirstPage(this.isFirstPage);
        newPageInfo.setIsLastPage(this.isLastPage);
        newPageInfo.setHasPreviousPage(this.hasPreviousPage);
        newPageInfo.setHasNextPage(this.hasNextPage);
        newPageInfo.setNavigatePages(this.navigatePages);
        newPageInfo.setNavigateFirstPage(this.navigateFirstPage);
        newPageInfo.setNavigateLastPage(this.navigateLastPage);
        newPageInfo.setNavigatepageNums(this.navigatepageNums);
        return newPageInfo;
    }

new PageInfo(list).convert(转换Fun);

@zjfplayer
Copy link
Author

我换了种使用方式就行了:

PageInfo page=new PageInfo(dbList);
page.setList(convertedList);

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