仿baidu,google的查询分页技术

在这里我简单说说我的实现思路,我将整个分页的技术全部封装在了一个Pagination的JavaBean中.具体代码如下:
Java代码
  1. package cn.csdn.util;  
  2.  
  3. import java.util.List;  
  4.  
  5. /**
  6. * @author redarmy_chen
  7. *
  8. * @param <T>
  9. */ 
  10. public class Pagination<T> {  
  11.  
  12.     // 分页信息  
  13.     private int nowpage;// 当前页 
  14.     private int countrecord;// 总记录 
  15.     private int countpage;// 总页数 
  16.  
  17.     public static final int PAGESIZE = 5;// 每页显示的记录数 
  18.  
  19.     private int startpage;// 页面中的起始页 
  20.     private int endpage;// 页面中的结束页 
  21.  
  22.     private final int SHOWPAGE = 6;// 页面中显示的总页数 baidu,google显示的总页数是20 
  23.     // 在测试我们才用6来测试 
  24.  
  25.     private List<T> allentities;  
  26.  
  27.     private String url;  
  28.  
  29.     /** 根据当前页及总记录数来构造分页对象 */ 
  30.     public Pagination(int nowpage, int countrecord) {  
  31.         this.nowpage = nowpage;  
  32.         this.countrecord = countrecord;  
  33.  
  34.         /** 计算总页数 */ 
  35.         this.countpage = this.countrecord % this.PAGESIZE == 0 ? this.countrecord  
  36.                 / this.PAGESIZE  
  37.                 : this.countrecord / this.PAGESIZE + 1;  
  38.  
  39.         /** 计算startpage与endpage的值 */ 
  40.  
  41.         /** 总页数数是否小于4 */ 
  42.         if (this.countpage < (this.SHOWPAGE / 2 + 1)) {  
  43.             this.startpage = 1; // 页面中起始页就是1 
  44.             this.endpage = this.countpage;// 页面中的最终页就是总页数 
  45.         } else {  
  46.             /** else中是总页数大于4的情况 */ 
  47.  
  48.             /** 首先当前页的值是否小于等于4 */ 
  49.             if (this.nowpage <= (this.SHOWPAGE / 2 + 1)) {  
  50.                 this.startpage = 1;  
  51.                 this.endpage = this.nowpage + 2;  
  52.                 /** 判断页面的最终页是否大于总页数 */ 
  53.                 if (this.endpage >= this.countpage) {  
  54.                     this.endpage = this.countpage;  
  55.                 }  
  56.             } else {  
  57.                 this.startpage = this.nowpage - 3;  
  58.                 this.endpage = this.nowpage + 2;  
  59.  
  60.                 if (this.endpage >= this.countpage) {  
  61.                     this.endpage = this.countpage;  
  62.                     if (this.countpage < this.SHOWPAGE) {  
  63.                         this.startpage = 1;  
  64.                     } else {  
  65.                         this.startpage = this.endpage - 5;  
  66.                     }  
  67.  
  68.                 }  
  69.             }  
  70.  
  71.         }  
  72.  
  73.     }  
  74.  
  75.     public int getNowpage() {  
  76.         return nowpage;  
  77.     }  
  78.  
  79.     public void setNowpage(int nowpage) {  
  80.         this.nowpage = nowpage;  
  81.     }  
  82.  
  83.     public int getCountrecord() {  
  84.         return countrecord;  
  85.     }  
  86.  
  87.     public void setCountrecord(int countrecord) {  
  88.         this.countrecord = countrecord;  
  89.     }  
  90.  
  91.     public int getCountpage() {  
  92.         return countpage;  
  93.     }  
  94.  
  95.     public void setCountpage(int countpage) {  
  96.         this.countpage = countpage;  
  97.     }  
  98.  
  99.     public int getStartpage() {  
  100.         return startpage;  
  101.     }  
  102.  
  103.     public void setStartpage(int startpage) {  
  104.         this.startpage = startpage;  
  105.     }  
  106.  
  107.     public int getEndpage() {  
  108.         return endpage;  
  109.     }  
  110.  
  111.     public void setEndpage(int endpage) {  
  112.         this.endpage = endpage;  
  113.     }  
  114.  
  115.     public List<T> getAllentities() {  
  116.         return allentities;  
  117.     }  
  118.  
  119.     public void setAllentities(List<T> allentities) {  
  120.         this.allentities = allentities;  
  121.     }  
  122.  
  123.     public String getUrl() {  
  124.         return url;  
  125.     }  
  126.  
  127.     public void setUrl(String url) {  
  128.         this.url = url;  
  129.     }  
  130.  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值