在javaweb开发中,经常要对查询出来的数据进行分类,但是分页的对象内容都是大同小异,固定不变的,下面对分页类 PageUtil进行代码展示,该类中的内容直接可以在项目当中使用。
package com.common.utils; public class PageUtil { private int page; private int totalRecord; private int pageCount;//总页数 private int rows; //每页显示条数 public PageUtil(int page, int rows) { this.page = page; this.rows = rows; } public PageUtil(String page, String rows) { this.page = page==null?1:Integer.parseInt(page); this.rows = rows==null?15:Integer.parseInt(rows); } public int getPageCount() { pageCount=totalRecord%rows==0?totalRecord/rows:totalRecord/rows+1; return pageCount ; } public int getPage() { return page; } public void setPage(int page) { this.page = page; } public int getTotalRecord() { return totalRecord; } public void setTotalRecord(int totalRecord) { this.totalRecord = totalRecord; } public int getRows() { return rows; } public void setRows(int rows) { this.rows = rows; } public int getStartRecord(){ if((page-1)*rows>totalRecord) return rows; else return (page-1)*rows; } public int getEndRecord(){ return getStartRecord()+getRows(); } }