pagehelper 對List結果集分頁


public class PageUtil {
 
    public static <T> PageInfo<T> startPage(List<T> list, Integer pageNum, Integer pageSize) {
public Page<YyAccountWorehouseEntity.AccountListVo> getPage(YyAccountWorehouseEntity.QueryPage queryPage) {
    List<YyAccountWorehouseEntity.AccountListVo> list = yyAccountWorehouseMapper.getPage(queryPage);
    //創建Page類
    int pageNum = queryPage.getPage();
    if (pageNum == 0) {
        pageNum = 1;
    }
    int pageSize = queryPage.getLimit();
    Page page = new Page(pageNum, pageSize);
    //為Page類中的total屬性賦值
    page.setTotal(list.size());
    //計算當前需要顯示的數據下標起始值
    int startIndex = (pageNum - 1) * pageSize;
    int endIndex = Math.min(startIndex + pageSize, list.size());
    //從鏈表中截取需要顯示的子鏈表,並加入到Page
    List<YyAccountWorehouseEntity.AccountListVo> accountListVos = list.subList(startIndex, endIndex);
    page.setRecords(accountListVos);
    //以Page創建PageInfo
    return page;
}



 
}
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM