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

com.github.xphsc.page.PageImpl Maven / Gradle / Ivy

There is a newer version: 1.2.3
Show newest version
package com.github.xphsc.page;

import java.util.List;

/**
 * Created by ${huipei.x} on 2017-6-18.
 */
public class PageImpl extends Page{

    public PageImpl(){}

    public PageImpl(int currentPage, int pageSize, long recordCount, List recordList) {
        this.currentPage = currentPage;
        if(currentPage < 1) {
            this.currentPage = 1;
        }

        this.pageSize = pageSize;
        this.recordCount = recordCount;
        this.recordList = recordList;
        //上一页等于当前页减一
        this.prePage = this.currentPage - 1;
        if(this.prePage < 1) {
            this.hasPrePage = false;//没有上一页
            this.prePage = 1;
        }else {
            this.hasPrePage = true;//有上一页
        }

        //计算总页数
        this.pageCount = (int)Math.ceil(recordCount / (double)pageSize);
        if(this.currentPage > this.pageCount) {
            this.currentPage = this.pageCount;
        }

        //下一页等于当前页加一
        this.nextPage = this.currentPage + 1;
        if(this.nextPage > this.pageCount) {
            this.hasNextPage = false;//没有下一页
            this.nextPage = this.pageCount;
        }else {
            this.hasNextPage = true;//有下一页
        }

        //偏移量
        this.offset = (this.currentPage - 1)*pageSize;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy