All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.amossun.starter.common.util.Page Maven / Gradle / Ivy

package cn.amossun.starter.common.util;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: starter-parent
 * @description:
 * @author: Amos.Sun
 * @DateTime: 2020/03/19 19:49
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Page {

    private int size = 15;

    private int current = 1;

    private List records;

    private int total;

    private int pages;

    public List computeRecords(List allRecords) {
        if(ObjectUtil.isEmpty(allRecords)) {
            return new ArrayList<>(0);
        }
        this.total = allRecords.size();
        this.records = ListUtil.page(current - 1, size, allRecords);
        return records;
    }

    public int getPages() {
        if (getSize() == 0 || getTotal() == 0 ) {
            return 0;
        }
        int pages = getTotal() / getSize();
        if (getTotal() % getSize() != 0) {
            pages++;
        }
        return pages;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy