list分页(包含怎么调用分页的例子)

时间:2014-08-28 11:27:41
【文件属性】:

文件名称:list分页(包含怎么调用分页的例子)

文件大小:4KB

文件格式:RAR

更新时间:2014-08-28 11:27:41

list 分页 jsp struts

list的分页 import java.util.ArrayList; import java.util.List; import com.jsp.vo.Client; /** * PageBean * * @author apple * */ public class Page { private int currentPage; // 当前页数 private int totalPages; // 总页数 private int pageRows =8; // 每页显示记录数 private int totalRows; // 总数据数 private int specPages; // 指定页数 private int pageStartRow ; // 每页的起始数 private int pageEndRow; // 每页的终止数 private boolean hasNextPage; // 是否有下一页 private boolean hasPreviousPage; // 是否有前一页 private List list; /** * 初始化对象 * * @param tempList * 结果集 * */ public Page(List tempList,int pageRows) { this.list = tempList; this.pageRows = pageRows; this.totalRows = tempList.size(); this.currentPage = 1; // 获取总页数 if ((totalRows % pageRows) == 0) { totalPages = totalRows / pageRows; if(this.totalRows == 0 ){ this.pageRows = 0; } } else { totalPages = totalRows / pageRows + 1; } this.hasPreviousPage = false; // 是否有下一页 if (currentPage == totalPages) { hasNextPage = false; } else { hasNextPage = true; } this.pageStartRow = 0; if (totalRows < pageRows) { this.pageEndRow = totalRows; } else { this.pageEndRow = pageRows; } } /** * 获取当前页的对象集合 * * @return List 对象集合 */ public List getCurrentPageList() { if (currentPage * pageRows < totalRows) { pageEndRow = currentPage * pageRows; pageStartRow = pageEndRow - pageRows; } else { pageEndRow = totalRows; pageStartRow = pageRows * (totalPages - 1); } List pageList = new ArrayList(); for (int i = pageStartRow; i < pageEndRow; i++) { pageList.add(list.get(i)); } return pageList; } /** * 获取上一页的对象集合 * * @return List 对象集合 */ public List getPreviousPage() { currentPage--; if (currentPage < 1) { currentPage = 1; } if (currentPage >= totalPages) { hasNextPage = false; } else { hasNextPage = true; } if ((currentPage - 1) > 0) { hasPreviousPage = true; } else { hasPreviousPage = false; } List pageList = getCurrentPageList(); return pageList; } /** * 获取下一页的对象集合 * * @return List 对象集合 */ public List getNextPage() { currentPage++; if ((currentPage - 1) > 0) { hasPreviousPage = true; } else { hasPreviousPage = false; } if (currentPage >= totalPages) { hasNextPage = false; } else { hasNextPage = true; } List pageList = getCurrentPageList(); return pageList; } /** * 获取第一页 * * @return List 对象集合 */ public List getFirstList() { List tempList = new ArrayList(); currentPage = 1; int a = pageRows; if(pageRows > this.totalRows){ a = this.totalRows; this.hasPreviousPage = false; this.hasNextPage = false; }else{ this.hasPreviousPage = false; this.hasNextPage = true; } for (int i = 0; i < a; i++) { tempList.add(list.get(i)); } return tempList; } /** * 获取最后一页 * * @return List 最后一页对象集合 */ public List getLastList() { List tempList = new ArrayList(); currentPage = totalPages; if(pageRows >= totalRows){ this.hasPreviousPage = false; this.hasNextPage = false; }else{ this.hasNextPage = false; this.hasPreviousPage = true; } for (int i = pageRows*(totalPages-1); i < this.totalRows; i++) { tempList.add(list.get(i)); } return tempList; } /** * 获取指定页 * * @return List 获取指定页对象集合 */ public List AppointPageList(int specPages) { List tempList = new ArrayList(); this.currentPage = specPages; if(currentPage > this.totalPages){ this.currentPage = this.totalPages; } if(currentPage < 1){ this.currentPage = 1; }else{ this.hasPreviousPage = false; } if(currentPage > 1){ this.hasPreviousPage = true; }else{ this.hasPreviousPage = false; } if(this.currentPage < this.totalPages){ this.hasNextPage = true; }else{ this.hasNextPage = false; } List pageList = this.getCurrentPageList(); return pageList; }


【文件预览】:
list分页
----listClientsServlet.java(3KB)
----listClient.jsp(3KB)
楬瑳횷돒停条⹥慪慶

网友评论

  • 代码不全!!
  • 很不错,正和我用