各位大虾,谁有完整的分页实现程序 ,最好是javabean的?

zl_xue 2002-08-02 04:40:26
各位大虾,谁有完整的分页实现程序 ,最好是javabean的?程序代码含 javabean代码。急用!!小弟先谢了
...全文
31 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zl_xue 2002-08-02
  • 打赏
  • 举报
回复
不知道好不好用???
先谢了 restart2001
restart2001 2002-08-02
  • 打赏
  • 举报
回复
在jsp页面调用:
MultiPageList mListOnDraft = new MultiPageList(arrCapitalPayOut,5);
String strNowPage2 = request.getParameter("iNowPage2");
int iTotalPage2 = mListOnDraft.getTotalPage();
int iNowPage2 = (strNowPage2 == null)?1: new Integer(request.getParameter("iNowPage2")).intValue();
out.print("共有 " + iTotalPage2 +" 页," ) ;
out.print("当前显示第 " + iNowPage2 + " 页 ") ;
mListOnDraft.setCurrentPage(iNowPage2) ;
if (iNowPage2 > 1)
{
out.print("<a href=index.jsp?iNowPage2=" + (iNowPage2-1) + "&year="+ m_iYear + "&month="+m_iMonth+"&EndMonth="+ m_iEndMonth+"&Department="+ myDepartmentCode+"&EndMonth="+ m_iEndMonth +">上一页</a>"+" ") ;
}
if (iNowPage2 < iTotalPage2)
{
out.print("<a href=index.jsp?iNowPage2=" + (iNowPage2+1) + "&year="+ m_iYear + "&month="+m_iMonth+"&EndMonth="+ m_iEndMonth+"&Department="+ myDepartmentCode +"&EndMonth="+ m_iEndMonth +">下一页</a>"+" ") ;
restart2001 2002-08-02
  • 打赏
  • 举报
回复
package com.xingtong.cms.web;

import java.util.*;
import com.xingtong.cms.db.*;

/**
* Title: Contract Managment System
* Description: For Xinanjiang electronic power factory
* Copyright: Copyright (c) 2002
* Company: Sino Tele.
* @author Zhangyx
* @version 1.0
*/

public class MultiPageList {

private ArrayList alList = null;
private int pageSize = 15;
private int totalPage = 0;
private int currentPage = 0;

/**
方法名称:MultiPageList
输入:ArrayList
输出:
说明:无参数构建器,默认记录条数为15
**/

public MultiPageList(ArrayList alList)
{
this.alList = alList;

if(alList != null && alList.size() > 0)
{
totalPage = alList.size() / pageSize;
if(alList.size() % pageSize > 0)
totalPage++;
currentPage = 1;
}

}


/**
方法名称:MultiPageList
输入:ArrayList,int
输出:
说明:带参数的构建器,记录数为pagesize
**/
public MultiPageList(ArrayList alList, int pageSize)
{
this.alList = alList;
this.pageSize = pageSize;

if(alList != null && alList.size() > 0)
{
totalPage = alList.size() / pageSize;
if(alList.size() % pageSize > 0)
totalPage++;
currentPage = 1;
}
}

/**
方法名称:getCurrentPage
输入:
输出: int
说明:得到当前页数
**/
public int getCurrentPage()
{
return currentPage;
}

/**
方法名称:setCurrentPage
输入:int
输出:无
说明:设置当前页数
**/
public void setCurrentPage(int currentPage)
{
if(currentPage > 0 && currentPage <= totalPage)
this.currentPage = currentPage;
}

/**
方法名称:getPageSize
输入:
输出: int
说明:得到一页所显示的记录数
**/
public int getPageSize()
{
return pageSize;
}

/**
方法名称:setPageSize
输入:int
输出:
说明:设置一页所显示的记录数
**/
public void setPageSize(int pageSize)
{
this.pageSize = pageSize;
totalPage = alList.size() / pageSize;
if(alList.size() % pageSize > 0)
totalPage++;
}

/**
方法名称:getTotalPage
输入:
输出: int
说明:得到所有的页数
**/
public int getTotalPage()
{
return totalPage;
}

public boolean hasNext()
{
if(currentPage == totalPage)
return false;

return true;
}

public boolean hasPrevious()
{
if(currentPage <= 1)
return false;

return true;
}

public void setLast()
{
currentPage = totalPage;
}

public void setFirst()
{
currentPage = 1;
}

public boolean setNext()
{
if(currentPage < totalPage)
{
currentPage++;
return true;
}

return false;
}

public boolean setPrevious()
{
if(currentPage > 1)
{
currentPage--;
return true;
}

return false;
}

public Object[] getByArray()
{
Object[] curObj = null;

if(currentPage < totalPage)
{
curObj = new Object[pageSize];
}
else
{
int size = alList.size() % pageSize;
curObj = new Object[(size == 0) ? pageSize : size];
}

for(int i=0; i<curObj.length; i++)
{
curObj[i] = alList.get((currentPage-1) * pageSize + i);
}

return curObj;
}

public ArrayList getByArrayList()
{
ArrayList alRet = new ArrayList();
int iLen;

if(currentPage < totalPage)
{
iLen = pageSize;
}
else
{
iLen = alList.size() % pageSize;
if(iLen == 0)
iLen = pageSize;
}

for(int i=0; i<iLen; i++)
{
Object obj = alList.get((currentPage-1) * pageSize + i);
alRet.add(obj);
}

if(alRet.size() <= 0)
alList = null;

return alRet;

}

public static void main(String[] args)
{
EmployeeBean eBean = new EmployeeBean();
ArrayList alModel = eBean.listAllEmployee();

System.out.println("employe count:"+alModel.size());

MultiPageList mList = new MultiPageList(alModel,16);
System.out.println("total page:"+mList.getTotalPage() );
System.out.println("current Page:"+mList.getCurrentPage());

// mList.setCurrentPage(4);
mList.setNext();
mList.setLast();

Object[] myObj = mList.getByArray();
for(int i=0; i<myObj.length; i++)
{
EmployeeModel eModel = (EmployeeModel)myObj[i];
System.out.println("array:"+eModel);
}

ArrayList alList = mList.getByArrayList();
Iterator iter = alList.iterator();
while(iter.hasNext())
{
EmployeeModel theModel = (EmployeeModel)iter.next();
System.out.println("list:"+theModel);
}

}
}


ajzhn 2002-08-02
  • 打赏
  • 举报
回复
//:BoardListBean.java
//公告牌中使用的bean

package zhnbean.infologin;

import java.sql.*;
import java.util.*;
import zhnbean.infologin.ViewQueryBean;

/*************************************************
* 为在JSP中编辑公告牌内容列表而使用的bean
* 具有多种属性,通过这些属性可以把数据转换成公告牌内容形态
*************************************************/

public class BoardListBean
{
// Database Wrapper class 声明
private ViewQueryBean viewquery = null;

//表
private String table;

//列名的数组
private String[] columns;

//条件查询的字符串
private String condquery;

//order-key;
private String order_key;

//当前显示的页面
private int current_page_num;

//显示在当前页面中的记录个数
private int no_rows = 10;

//如果没有数据选项就返回true
private boolean isEmpty;

//全部记录数
private int total_count;

//全部页数
private int total_page;

//当前在公告版中显示的记录数
private int showed_count = 0;

/***********************************
* 生成方法
************************************/
public BoardListBean()
{
viewquery = new zhnbean.infologin.ViewQueryBean();
viewquery.openConnection();
}

/***********************************
* 设定数据库表的方法
************************************/
public void setTable(String table)
{
this.table = table;
}

/***********************************
* 设定各个表的列的方法
************************************/
public void setColumns(String[] columns)
{
this.columns = columns;
}

/***********************************
* 调出目录时,设定决定排列方式的列的方法
************************************/
public void setOrder(String order_key)
{
this.order_key = order_key;
}

/***********************************
* 设定希望游览的页面的方法
************************************/
public void setPage(int page)
{
this.current_page_num = page;
}

/***********************************
* 设定条件查询的字符串
************************************/
public void setCondquery(String condquery)
{
this.condquery = condquery;
}

/*************************************
*驱动Bean的方法
*************************************/
public void init()
{
try
{
//step 1:为了获取全部数据的信息,求出所有记录的个数
initCount();

//step 2:SQL组合Query语句
String query = makeQuery();

//step 3:利用组合好的SQL Query语句,向数据库提出问题

initData(query);

//ster 4: 把Result Set 的指针移动到指定的页码的记录
getPoint_of_ResultSet();
}
catch (Exception e)
{
}
}


/*************************************
* 这是求出全部记录数的方法
*************************************/
private void initCount()
{
StringBuffer query = new StringBuffer();
query.append("select COUNT(*) FROM "+this.table);

//组合检索键的询问语句
if(this.condquery != null && !this.condquery.equals("")){
query.append(" where "+this.condquery);
}

try
{
//String query1 = "select COUNT(*) from students ";
//向数据提出查询
viewquery.executeQuery(query.toString());

if(viewquery.next()){

//求出全部记录数
this.total_count = Integer.parseInt(viewquery.getData(1));

//当记录数为0时,把isEmpty属性,设定为true
if(total_count ==0) isEmpty = true;

// 求出最后一页的页码,首页从1 开始
this.total_page = total_count/no_rows+1;
if( (this.total_count % no_rows) == 0){
this.total_page = this.total_page - 1;
}
}
}
catch(SQLException e)
{
}
}

/*************************************
* 这是具备所有指定条件并组合出正确的查询语句的方法
*************************************/
private String makeQuery()
{
StringBuffer query = new StringBuffer();
query.append("select ");

//step 1:组合设定值field 时所需的查询语句
for(int i=0;i<this.columns.length;i++){
query.append(columns[i]);
if(i!=this.columns.length-1){
query.append(", ");
}
}

//step 2:组合设定表时所需的查询语句
query.append(" FROM " + this.table);


//step 3:组合检索键的询问语句
if(this.condquery != null && !this.condquery.equals("")){
query.append(" WHERE " + this.condquery);
}

//step 4:组合排列所需的查询语句
if(this.order_key != null && !this.order_key.equals("")){
query.append(" ORDER BY " + this.order_key);
}

//step 5:返回组合好的查询语句
return query.toString();
}

/******************************************
*把SQL查询信息传到数据库的方法
***************************************/
private void initData(String query) throws SQLException
{
try{
viewquery.executeQuery(query);
}catch (SQLException e){
}
}

/******************************************
*为了只浏览指定页码的数据信息, 把ResultSet指针移动到指定页 码
***************************************/
private void getPoint_of_ResultSet() throws SQLException
{
for(int i=1;i<current_page_num;i++){
for(int j=0;j<no_rows;j++){
viewquery.next();
}
}
}

/******************************************
*这是以字符串形式返回在Record Set中 指定的列的数据信息的方法
*如果没有数据,就返回空的字符串
***************************************/
public String getData(String columnName) throws SQLException
{
return viewquery.getData(columnName)!=null?viewquery.getData(columnName):"";
}

/******************************************
*这是以字符串形式返回在Record Set中 指定的列的数据信息的方法
*如果没有数据,就返回空的字符串
***************************************/
public String getData(int index) throws SQLException
{
return viewquery.getData(index)!=null?viewquery.getData(index):"";
}

/*******************************************************
* 1.在指定页面中,在数据的有效输出时间内返回true
* 2.在ResultSet中,把指针移动到下一个位置
********************************************************/
public boolean isAvailable() throws SQLException
{
if( viewquery != null && viewquery.next() && showed_count++ < no_rows){
return true;
}
return false;
}

/*************************************
*在没有数据时,返回true的方法
*************************************/
public boolean isEmpty()
{
return isEmpty;
}

/*************************************
*返回当前设定的页的方法
*************************************/
public int getCurrentPage()
{
return this.current_page_num;
}


/*************************************
*返回公告牌内容总页数的方法
*************************************/
public int getLastPage()
{
return this.total_page;
}


/*************************************
*返回当前页面中显示的记录数的方法
*************************************/
public int getShowedCount()
{
return showed_count;
}

/*************************************
*返回符合所选条件的总记录数
*************************************/
public int getTotal_Count()
{
return total_count;
}


/*************************************
*在Web服务器停止运行时,进行资源回收的方法
*************************************/
protected void finalize() throws Throwable
{
if(viewquery != null){
viewquery.close();
}
}
}







zl_xue 2002-08-02
  • 打赏
  • 举报
回复
拜托!老兄。那个是我留的!!但解决不了我的问题!!!
给个完整的!!谢谢
Andrawu 2002-08-02
  • 打赏
  • 举报
回复
http://www.csdn.net/expert/topic/915/915630.xml?temp=3.049868E-02

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧