天天看點

對多次查詢資料庫得到的資料集合進行分頁處理

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
</dependency>      

//使用分頁插件對過濾後的資料進行分頁

    Page page = new Page(pageNum, pageSize);

    int total = resultList.size();

    page.setTotal(total);

    int startIndex = (pageNum-1) * pageSize;

    int endIndex = Math.min(startIndex + pageSize,total);

    page.addAll(resultList.subList(startIndex, endIndex));

    PageInfo pageInfo = new PageInfo<>(page);

接下來可以将PageInfo做處理,放在自定義的分頁實體類中

繼續閱讀