实现手动分页

1.IPage

IPage info = new Page<>();

@Override
    public IPage<DAlarmDetail> findPageAndList(DAlarmInfoVO vo) {

        List<DAlarmDetail> dAlarmDetails = getDAlarmDetails(vo);
        IPage<DAlarmDetail> info = new Page<>();

        int total = dAlarmDetails.size();
        int pageNum = vo.getPageNum();
        int pageSize = vo.getPageSize();

        if(total>0) {
            if (total <= pageNum * pageSize) {
                info.setRecords(dAlarmDetails.subList((pageNum-1) * pageSize, total));
            } else {
                info.setRecords(dAlarmDetails.subList((pageNum-1) * vo.getPageSize(), pageNum * pageSize));
            }
        }
        info.setCurrent(pageNum);
        info.setSize(pageSize);
        info.setTotal(total);
        return info;
    }

2.stream().skip

Page<XX> page = new Page<>;
XXXXXX
page.setRecords(xxList.stream().skip((long)(Math.max(1,current) -1)*pageSize).limit(pageSize).collect(Collectors.toList()));

你可能感兴趣的:(工具,SQL,分页)