03-内存分页

2021-11-19  本文已影响0人  糖纸疯了

1、写作背景

懒惰象生锈一样,比操劳更能消耗身体。


2、参考网址


3、学习目的


4、核心操作

1)内存分页工具

import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class TableDataInfo<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer total;
    private Integer startIndex;
    private Integer pageSize;
    private transient List<T> rows;

    public TableDataInfo(List<T> list, Integer startIndex, Integer pageSize) {
        // 兼容
        startIndex = null == startIndex ? 1 : startIndex;
        startIndex = startIndex == 0 ? 1 : startIndex;
        pageSize = null == pageSize ? 10 : pageSize;
        List<T> resultList = null;

        // 赋值
        this.startIndex = startIndex;
        this.pageSize = pageSize;
        this.rows = list;

        // 手动分页
        int beginIndex = (startIndex - 1) * pageSize;
        int endIndex = startIndex * pageSize;

        if (beginIndex > list.size() - 1) {
            this.rows = null;
        } else if (endIndex >= list.size()) {
            resultList = list.subList(beginIndex, list.size());
        } else {
            resultList = list.subList(beginIndex, endIndex);
        }
        this.rows = resultList;
    }
}
    public static TableDataInfo<String> getRageInfoData(){
        List<String> list = Arrays.asList("01", "02", "03", "04", "05", "06", "07", "08");
        return new TableDataInfo<>(list,1,2);
    }

5、课后习题

1)XXXX


上一篇 下一篇

猜你喜欢

热点阅读