码迷,mamicode.com
首页 > 编程语言 > 详细

Java Web分页类分享

时间:2015-05-12 11:23:32      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:java web

分页类分享:

package com.hcj.util;

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

import org.apache.struts2.json.annotations.JSON;

//分页类
public class Page<E> {
	private int totals; //查询到的总数量
	 
    private List<E> bigList ;  //总记录集
 
    private List<E> smallList; //当页显示的记录集
 
    private int currentPage = 1;  //当前页
 
    private int pages;  //总页数
 
    private int pageSize = 8; //每页记录数
 
    private int privious; //上一页
 
    private int next; //下一页
 
    private boolean firstPage = false;//第一页
 
    private boolean lastPage = false; //最后一页


    public int getTotals() {
		return totals;
	}

	public void setTotals(int totals) {
		this.totals = totals;
	}
	
	@JSON(serialize=false)  
	public List<E> getBigList() {
		return bigList;
	}

	public void setBigList(List<E> bigList) {
		this.bigList = bigList;
	}

	public List<E> getSmallList() {
		this.smallList = new ArrayList<E>();
        for (int i = (currentPage - 1) * pageSize; (i < currentPage* pageSize)&& (i < totals); i++) {
            smallList.add(bigList.get(i));
        }
        return smallList;
	}

	public void setSmallList(List<E> smallList) {
		this.smallList = smallList;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPages() {
		if (totals % pageSize == 0) {
            pages = totals / pageSize;
        } else {
            pages = totals / pageSize + 1;
        }
		return pages;
	}

	public void setPages(int pages) {
		this.pages = pages;
	}

	public int getPageSize() {
		return pageSize;
	}

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

	public int getPrivious() {
		if(currentPage != 1){
    		privious = currentPage - 1;
    	}else{
    		privious = 1;
    	}
		return privious;
	}

	public void setPrivious(int privious) {
		this.privious = privious;
	}

	public int getNext() {
		if(currentPage != getPages()){
    		next = currentPage + 1;
    	}else{
    		next = currentPage;
    	}
		return next;
	}

	public void setNext(int next) {
		this.next = next;
	}

	public boolean isFirstPage() {
		if(currentPage == 1){
    		firstPage = true;
    	}
		return firstPage;
	}

	public void setFirstPage(boolean firstPage) {
		this.firstPage = firstPage;
	}

	public boolean isLastPage() {
		if(currentPage == getPages()){
    		lastPage = true;
    	}
		return lastPage;
	}

	public void setLastPage(boolean lastPage) {
		this.lastPage = lastPage;
	}

	public Page() {
		super();
		// TODO Auto-generated constructor stub
	}

	//输入总结果,当前页和每页大小(默认为8页)
	public Page(List<E> bigList, int currentPage, int pageSize) {
		super();
		this.bigList = bigList;
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		//设置总的total,这步很重要
		this.setTotals(bigList.size());
	}

	public Page(List<E> bigList, int currentPage) {
		super();
		this.bigList = bigList;
		this.currentPage = currentPage;
		this.setTotals(bigList.size());
	}
    
    
    
}


Java Web分页类分享

标签:java web

原文地址:http://blog.csdn.net/u011768325/article/details/45666527

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!