您当前的位置: 首页 >  服务器

梁云亮

暂无认证

  • 0浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

封装服务器端返回分页结果的JavaBean

梁云亮 发布时间:2019-11-15 11:03:41 ,浏览量:0

封装服务器端返回分页结果的Bean

服务器端返回结果一般情况下需要分页,下面实体类封装了服务器端返回的带有分页功能的Bean

public class PageBean {
	
	//当前页显示的数据
    private List records;
    //当前页码
    private long currentPageNum;  
    //总页码
    private long totalPageNum;    
    //每页显示的记录条数
    private long pageSize = GlobalConst.PAGE_SIZE; 
    //总记录条数
    private long totalRecordsAmount;    
    //上一页
    private long prePageNum;
    //下一页
    private long nextPageNum;    
    //查询分页的请求的地址(通过这个属性可以将页面中的分页部分给抽取成公共部分)
    private String url;   

    public PageBean() {
    }

    public List getRecords() {
        return records;
    }

    public void setRecords(List records) {
        this.records = records;
    }

    public long getCurrentPageNum() {
		return currentPageNum;
	}

	public void setCurrentPageNum(long currentPageNum) {
		this.currentPageNum = currentPageNum;
	}

	public long getTotalPageNum() {
        return totalPageNum;
    }

    public long getPrePageNum() {
        prePageNum = currentPageNum - 1;
        if (prePageNum  totalPageNum) {
            nextPageNum = totalPageNum;
        }
        return nextPageNum;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotalRecordsAmount() {
        return totalRecordsAmount;
    }

    public void setTotalRecordsAmount(long totalRecordsAmount) {
        this.totalRecordsAmount = totalRecordsAmount;
        //当设置记录总条数时,自动计算出共有多少页
        this.totalPageNum = totalRecordsAmount%pageSize==0?totalRecordsAmount/pageSize:totalRecordsAmount/pageSize+1;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        for (T t : records) {
            sb.append(t).append("\n");
        }
        return "PageBean{\n" +
                "currentPageNum=" + currentPageNum +
                ", totalPageNum=" + totalPageNum +
                ", pageSize=" + pageSize +
                ", totalRecordsAmount=" + totalRecordsAmount +
                ", prePageNum=" + getPrePageNum() +
                ", nextPageNum=" + getNextPageNum() +
                ", url=" + url +",\n"+
                "records=" + sb +
                '}';
    }
    
}
关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0405s