有关java编程

zodiac的学习笔记

统计

留言簿(1)

阅读排行榜

评论排行榜

一个通用的查询结果页面对象

通常,此类对象放在项目的vo包中。
PageBean.java代码:
package org.zodiac.vo;

import java.util.List;

/**查询结果页面对象
 * 
 
*/

public class PageBean {

    
private static final long serialVersionUID = 8167148510462280050L;

    
private static Integer defaulfRowsPerPage = new Integer(50);

    
private Integer rowsPerPage;

    
private Integer currentPage;

    
private Long totalRows;

    
private Integer totalPages;

    
private Integer startIndex;

    
private Integer endIndex;

    
private Integer nextPage;// 下一页的页码

    
private Integer previousPage;// 上一页的页码

    
private Boolean hasNextPage;// 是否有下一页

    
private Boolean hasPreviousPage;// 是否有前一页

    
private List<?> list;
    
    
private IQueryCondition queryCondition;//查询条件对象

    
public PageBean(QueryCondition queryCondition) {
        
super();
        
this.queryCondition = queryCondition;
        
        
if (queryCondition==null||queryCondition.getCurrentPage() == null{
            
this.currentPage = new Integer(1);
        }
 else {
            
this.currentPage = queryCondition.getCurrentPage();
        }

        
this.rowsPerPage = defaulfRowsPerPage;
    }


    
public PageBean(Integer currentPage, Integer rowsPerPage) {
        
super();
        
if (currentPage == null{
            
this.currentPage = new Integer(1);
        }
 else {
            
this.currentPage = currentPage;
        }

        
if (rowsPerPage == null || rowsPerPage.intValue() < 1{
            
this.rowsPerPage = defaulfRowsPerPage;
        }
 else {
            
this.rowsPerPage = rowsPerPage;
        }

    }


    
/**
     * 设置总数量,计算全部其他参数
     * 
     * 
@param totalRows
     
*/

    
public void setTotalRows(Long totalRows) {
        
this.totalRows = totalRows;

        
// 计算总页数
        if ((totalRows.longValue() % rowsPerPage.intValue()) == 0{
            totalPages 
= new Integer((int) (totalRows.longValue() / rowsPerPage.intValue()));
        }
 else {
            totalPages 
= new Integer((int) (totalRows.longValue() / rowsPerPage.intValue() + 1));
        }

        
// 计算下一页
        if (totalPages.compareTo(this.currentPage) > 0{
            hasNextPage 
= Boolean.TRUE;
            nextPage 
= new Integer(currentPage.intValue() + 1);
        }
 else {
            currentPage 
= totalPages;
            hasNextPage 
= Boolean.FALSE;
            nextPage 
= totalPages;
        }

        
// 计算上一页
        if (this.currentPage.intValue() > 1{
            hasPreviousPage 
= Boolean.TRUE;
            previousPage 
= new Integer(currentPage.intValue() - 1);
        }
 else {
            currentPage 
= new Integer(1);
            hasPreviousPage 
= Boolean.FALSE;
            previousPage 
= new Integer(1);
        }

        
// 计算当前页的起止行
        endIndex = new Integer(currentPage.intValue() * rowsPerPage.intValue());
        startIndex 
= new Integer(endIndex.intValue() - rowsPerPage.intValue() + 1);
    }


    
public Integer getCurrentPage() {
        
return currentPage;
    }


    
public Integer getEndIndex() {
        
return endIndex;
    }


    
public Boolean getHasNextPage() {
        
return hasNextPage;
    }


    
public Boolean getHasPreviousPage() {
        
return hasPreviousPage;
    }


    
public Integer getNextPage() {
        
return nextPage;
    }


    
public Integer getPreviousPage() {
        
return previousPage;
    }


    
public Integer getRowsPerPage() {
        
return rowsPerPage;
    }


    
public Integer getStartIndex() {
        
return startIndex;
    }


    
public Integer getTotalPages() {
        
return totalPages;
    }


    
public Long getTotalRows() {
        
return totalRows;
    }


    
public List<?> getList() {
        
return list;
    }


    
public void setList(List<?> list) {
        
this.list = list;
    }


    
public IQueryCondition getQueryCondition() {
        
return queryCondition;
    }


    
public void setQueryCondition(IQueryCondition queryCondition) {
        
this.queryCondition = queryCondition;
    }


}


IQueryCondition的实现就不罗嗦了。

posted on 2008-12-24 15:01 Zodiac 阅读(195) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: