仿baidu,google的查询分页技术
2011-11-03 10:33
330 查看
在上一节中我们简单观察与分析了仿baidu,google的查询分页技术,有很多学生纷纷的给我来了邮件,期待着使用Java技术的实现.在这里很感谢大家对我的关注,我会一如既往的在此平台之上发布自己的授课中一些知识点的总结.下将仿baidu,google查询分页技术的实现方式一种分享给大家,如有问题请及时发送邮件.希望同学们在这新的学期中有更大的收获。
在这里我简单说说我的实现思路,我将整个分页的技术全部封装在了一个Pagination的JavaBean中.具体代码如下:
Java代码
package cn.csdn.util;
import java.util.List;
/**
*
* @author redarmy_chen
*
* @param <T>
*/
public class Pagination<T> {
// 分页信息
private int nowpage;// 当前页
private int countrecord;// 总记录
private int countpage;// 总页数
public static final int PAGESIZE = 5;// 每页显示的记录数
private int startpage;// 页面中的起始页
private int endpage;// 页面中的结束页
private final int SHOWPAGE = 6;// 页面中显示的总页数 baidu,google显示的总页数是20
// 在测试我们才用6来测试
private List<T> allentities;
private String url;
/** 根据当前页及总记录数来构造分页对象 */
public Pagination(int nowpage, int countrecord) {
this.nowpage = nowpage;
this.countrecord = countrecord;
/** 计算总页数 */
this.countpage = this.countrecord % this.PAGESIZE == 0 ? this.countrecord
/ this.PAGESIZE
: this.countrecord / this.PAGESIZE + 1;
/** 计算startpage与endpage的值 */
/** 总页数数是否小于4 */
if (this.countpage < (this.SHOWPAGE / 2 + 1)) {
this.startpage = 1; // 页面中起始页就是1
this.endpage = this.countpage;// 页面中的最终页就是总页数
} else {
/** else中是总页数大于4的情况 */
/** 首先当前页的值是否小于等于4 */
if (this.nowpage <= (this.SHOWPAGE / 2 + 1)) {
this.startpage = 1;
this.endpage = this.nowpage + 2;
/** 判断页面的最终页是否大于总页数 */
if (this.endpage >= this.countpage) {
this.endpage = this.countpage;
}
} else {
this.startpage = this.nowpage - 3;
this.endpage = this.nowpage + 2;
if (this.endpage >= this.countpage) {
this.endpage = this.countpage;
if (this.countpage < this.SHOWPAGE) {
this.startpage = 1;
} else {
this.startpage = this.endpage - 5;
}
}
}
}
}
public int getNowpage() {
return nowpage;
}
public void setNowpage(int nowpage) {
this.nowpage = nowpage;
}
public int getCountrecord() {
return countrecord;
}
public void setCountrecord(int countrecord) {
this.countrecord = countrecord;
}
public int getCountpage() {
return countpage;
}
public void setCountpage(int countpage) {
this.countpage = countpage;
}
public int getStartpage() {
return startpage;
}
public void setStartpage(int startpage) {
this.startpage = startpage;
}
public int getEndpage() {
return endpage;
}
public void setEndpage(int endpage) {
this.endpage = endpage;
}
public List<T> getAllentities() {
return allentities;
}
public void setAllentities(List<T> allentities) {
this.allentities = allentities;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
在这里我简单说说我的实现思路,我将整个分页的技术全部封装在了一个Pagination的JavaBean中.具体代码如下:
Java代码
package cn.csdn.util;
import java.util.List;
/**
*
* @author redarmy_chen
*
* @param <T>
*/
public class Pagination<T> {
// 分页信息
private int nowpage;// 当前页
private int countrecord;// 总记录
private int countpage;// 总页数
public static final int PAGESIZE = 5;// 每页显示的记录数
private int startpage;// 页面中的起始页
private int endpage;// 页面中的结束页
private final int SHOWPAGE = 6;// 页面中显示的总页数 baidu,google显示的总页数是20
// 在测试我们才用6来测试
private List<T> allentities;
private String url;
/** 根据当前页及总记录数来构造分页对象 */
public Pagination(int nowpage, int countrecord) {
this.nowpage = nowpage;
this.countrecord = countrecord;
/** 计算总页数 */
this.countpage = this.countrecord % this.PAGESIZE == 0 ? this.countrecord
/ this.PAGESIZE
: this.countrecord / this.PAGESIZE + 1;
/** 计算startpage与endpage的值 */
/** 总页数数是否小于4 */
if (this.countpage < (this.SHOWPAGE / 2 + 1)) {
this.startpage = 1; // 页面中起始页就是1
this.endpage = this.countpage;// 页面中的最终页就是总页数
} else {
/** else中是总页数大于4的情况 */
/** 首先当前页的值是否小于等于4 */
if (this.nowpage <= (this.SHOWPAGE / 2 + 1)) {
this.startpage = 1;
this.endpage = this.nowpage + 2;
/** 判断页面的最终页是否大于总页数 */
if (this.endpage >= this.countpage) {
this.endpage = this.countpage;
}
} else {
this.startpage = this.nowpage - 3;
this.endpage = this.nowpage + 2;
if (this.endpage >= this.countpage) {
this.endpage = this.countpage;
if (this.countpage < this.SHOWPAGE) {
this.startpage = 1;
} else {
this.startpage = this.endpage - 5;
}
}
}
}
}
public int getNowpage() {
return nowpage;
}
public void setNowpage(int nowpage) {
this.nowpage = nowpage;
}
public int getCountrecord() {
return countrecord;
}
public void setCountrecord(int countrecord) {
this.countrecord = countrecord;
}
public int getCountpage() {
return countpage;
}
public void setCountpage(int countpage) {
this.countpage = countpage;
}
public int getStartpage() {
return startpage;
}
public void setStartpage(int startpage) {
this.startpage = startpage;
}
public int getEndpage() {
return endpage;
}
public void setEndpage(int endpage) {
this.endpage = endpage;
}
public List<T> getAllentities() {
return allentities;
}
public void setAllentities(List<T> allentities) {
this.allentities = allentities;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
相关文章推荐
- 仿baidu,google的查询分页技术
- 仿Baidu,Google查询分页技术实现分析
- 仿Baidu,Google查询分页技术实现分析
- 原创:仿Baidu,Google查询分页技术JAVA实现
- 原创: 仿Baidu,Google查询分页技术实现分析之一
- 仿Baidu,Google查询分页技术实现分析之一
- 每天看一遍 仿Baidu,Google查询分页技术JAVA实现
- 关于JAVA的分页查询操作技术
- EXT4.1 查询分页技术分享
- jqGrid分页技术学习(七)spring jdbc 分页查询DAO
- php google baidu 分页
- 20160327servlet学习笔记分页技术三层过滤的sql分页查询
- jqGrid分页技术学习(八)spring jdbc 单条件查询
- javaweb网上书店之分页技术---有get方法进行查询分页,而URL中包含"%"的出错处理
- jqGrid分页技术学习(九)spring jdbc多单条件组合查询
- iOS程序员利用分页和模糊查询技术实现一个App接口
- 认真做 flex + spring + blazeDS + google app JDO 分页.每次查询总数.
- 查询分页技术实现分析
- 搜索引擎 查询参数汇总(google、baidu、yahoo) 继续更新中。。