标签:
page 类代码分页查询代码
1 package com.pb.pager; 2 3 public class Pager { 4 /** 5 * 总页数 6 */ 7 private int totalcount = 0; 8 /** 9 * 页面大小,即每页显示记录数 10 */ 11 private int pageSize = 0; 12 /** 13 * 记录总数 14 */ 15 private int recordCount = 0; 16 17 /** 18 * 当前页号 19 */ 20 private int currPageNo=0; 21 22 public int getCurrPageNo() { 23 if(totalcount==0) 24 return 0; 25 return currPageNo; 26 } 27 28 public void setCurrPageNo(int currPageNo) { 29 if(currPageNo>0) 30 this.currPageNo = currPageNo; 31 } 32 33 public int getTotalcount() { 34 return totalcount; 35 } 36 37 public void setTotalcount(int totalcount) { 38 this.totalcount = totalcount; 39 } 40 41 public int getPageSize() { 42 return pageSize; 43 } 44 45 public void setPageSize(int pageSize) { 46 if (pageSize > 0) 47 this.pageSize = pageSize; 48 } 49 50 public int getRecordCount() { 51 return recordCount; 52 } 53 54 public void setRecordCount(int recordCount) { 55 if (recordCount > 0) 56 this.recordCount = recordCount; 57 } 58 59 // 设置总页数 60 private void setTotalpagecount() { 61 if (this.recordCount % this.pageSize == 0) { 62 this.recordCount = this.recordCount / this.pageSize; 63 } else if (this.recordCount % this.pageSize > 0) { 64 this.recordCount = this.recordCount / this.pageSize + 1; 65 }else{ 66 this.recordCount=0; 67 } 68 } 69 /** 70 * 开始记录数 71 * @return 72 */ 73 public int getStartRow(){ 74 return (currPageNo-1)*pageSize+1; 75 76 } 77 /** 78 * 结束记录数 79 * @return 80 */ 81 public int getEndRow(){ 82 return currPageNo*pageSize; 83 84 } 85 }
分页查询的步骤
(1).确定每页显示的数据数量
(2).计算显示数据的总数量
(3).计算显示的页数=总数量/每页显示的数据数量(+1)
(4)。编写分页查询SQl语句
(5).实现分页查询
使用CallbleStatement执行存储过程
1 public int getTotalcountProc() { 2 int totalCount=0; 3 CallableStatement proc=null; 4 String sql="{call PRO_GETTOTALCOUNT(?)}"; 5 getConnection(); 6 try { 7 proc=con.prepareCall(sql); 8 proc.registerOutParameter(1, Types.INTEGER); 9 proc.execute(); 10 totalCount=proc.getInt(1); 11 } catch (SQLException e) { 12 // TODO Auto-generated catch block 13 e.printStackTrace(); 14 } 15 16 // TODO Auto-generated method stub 17 return totalCount; 18 }
分页显示关键点
确定当前页
设置首页,上一页,下一页,末页的页码
首页和末页的控制
标签:
原文地址:http://www.cnblogs.com/wanghongjie/p/4598621.html