首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

一个分页的工具种

2012-11-23 
一个分页的工具类/** * Copyright(C)2012, Docworks Inc. All rights reserved. */package com.docworks.u

一个分页的工具类

/** * Copyright(C)2012, Docworks Inc. All rights reserved. */package com.docworks.util;/** * <p>该类用于计算分页信息</p> * @author: liuwei * @date 2012-9-26 */public class PageUtil {/** * 当前页 */private int currentPage;/** * 每页显示的条目数 */private int perPage;/** * 总记录数 */private int recordTotal;/** * 总页数 */private int pageTotal;/** * 起始索引位置 */private int startIndex;/** * 结束索引位置 */private int endIndex;/** * 无参数的构造方法 */public PageUtil() {}/** * <p>初始化页面信息,计算起始索引位置和结束索引位置的构造方法</p> * @param currentPage 当前页码 * @param perPage 每页显示的条目数,可以由{@link #setPerPage(int perPage)}修改 * @param recordTotal 总记录数 */public PageUtil(int currentPage, int perPage, int recordTotal) {this.currentPage = currentPage;this.perPage = perPage;this.recordTotal = recordTotal;int tempCount = 0;if (this.recordTotal != 0) {startIndex = (this.currentPage - 1) * this.perPage + 1;tempCount = this.currentPage * this.perPage;if (this.recordTotal < tempCount) {endIndex = this.recordTotal;} else {endIndex = tempCount;}}}/** * <p>计算总页数</p> * @return 总页数 */public int getPageTotal() {if (recordTotal < perPage) {pageTotal = 1;} else if (recordTotal % perPage == 0) {pageTotal = recordTotal / perPage;} else {pageTotal = recordTotal / perPage + 1;}return pageTotal;}/** * <p>获得起始索引位置</p> * @return 起始索引位置 */public int getStartIndex() {return startIndex;}/** * <p>获得结束索引位置</p> * @return 结束索引位置 */public int getEndIndex() {return endIndex;}/** * <p>获得当前页码</p> * @return 当前页码 */public int getCurrentPage() {return currentPage;}/** * <p>获得每页显示的条目数</p> * @return 每页显示的条目数 */public int getPerPage() {return perPage;}/** * <p>获得总记录数</p> * @return 总记录数 */public int getRecordTotal() {return recordTotal;}/** * <p>传入一个数字参数,设置每页显示的条目数</p> * @param perPage 要传入的参数,每页显示的条目数 */public void setPerPage(int perPage) {this.perPage = perPage;}}

热点排行