在项目中使用的实用hibernate 分页
来源:互联网 发布:做淘宝优惠券赚钱吗 编辑:程序博客网 时间:2024/05/19 01:11
将项目中使用的分页方法记录如下
PageIndex.java
package com.archermind.util;
/**
* 页索引,主要是起始页和终止页
*/
public class PageIndex
{
/** 开始索引 **/
private int startIndex;
/** 结束索引 **/
private int endIndex;
public PageIndex(int startIndex, int endIndex)
{
this.startIndex = startIndex;
this.endIndex = endIndex;
}
public int getStartIndex()
{
return startIndex;
}
public void setStartIndex(int startIndex)
{
this.startIndex = startIndex;
}
public int getEndIndex()
{
return endIndex;
}
public void setEndIndex(int endIndex)
{
this.endIndex = endIndex;
}
/**
* 起始页和终止页
*
* @param viewPageCount
* 显示多少页
* @param currentPage
* 当前页
* @param totalpage
* 总页数
* @return PageIndex 起始页和终止页
*/
public static PageIndex getPageIndex(int viewPageCount, int currentPage, int totalpage)
{
int startpage = currentPage - (viewPageCount % 2 == 0 ? viewPageCount / 2 - 1 : viewPageCount / 2);
int endpage = currentPage + viewPageCount / 2;
if (startpage < 1)
{
startpage = 1;
if (totalpage >= viewPageCount)
endpage = viewPageCount;
else
endpage = totalpage;
}
if (endpage > totalpage)
{
endpage = totalpage;
if ((endpage - viewPageCount) > 0)
startpage = endpage - viewPageCount + 1;
else
startpage = 1;
}
return new PageIndex(startpage, endpage);
}
}
QueryResult.java
package com.archermind.util;
import java.util.List;
/**
* 查询结果集,包括数据和总数
*
*/
public class QueryResult<T>
{
/** 查询得出的数据List **/
private List<T> resultList;
/** 查询得出的总数 **/
private int totalRecord;
public List<T> getResultList()
{
return resultList;
}
public void setResultList(List<T> resultList)
{
this.resultList = resultList;
}
public int getTotalRecord()
{
return totalRecord;
}
public void setTotalRecord(int totalRecord)
{
this.totalRecord = totalRecord;
}
}
PageView.java
package com.archermind.util;
import java.util.List;
public class PageView<T> {
/** 分页数据 **/
private List<T> records;
/** 页码开始索引和结束索引 **/
private PageIndex pageindex;
/** 总页数 **/
private long totalpage =1;
/** 每页显示记录数 **/
private int maxresult =10;
/** 当前页 **/
private int currentpage =1;
/** 总记录数 **/
private int totalrecord;
/** 页码数量 **/
private int pagecode =3;
/** 要获取记录的开始索引 **/
public int getFirstResult() {
return (this.currentpage-1)*this.maxresult;
}
public int getPagecode() {
return pagecode;
}
public void setPagecode(int pagecode) {
this.pagecode = pagecode;
}
public PageView(){}
public PageView(int maxresult, int currentpage) {
this.maxresult = maxresult;
this.currentpage = currentpage;
}
public void setQueryResult(QueryResult<T> qr){
setTotalrecord(qr.getTotalRecord());
setRecords(qr.getResultList());
}
public long getTotalrecord() {
return totalrecord;
}
public void setTotalrecord(int totalrecord) {
this.totalrecord = totalrecord;
setTotalpage(this.totalrecord%this.maxresult==0?this.totalrecord/this.maxresult : this.totalrecord/this.maxresult+1);
}
public List<T> getRecords() {
return records;
}
public void setRecords(List<T> records) {
this.records = records;
}
public PageIndex getPageindex() {
return pageindex;
}
public long getTotalpage() {
return totalpage;
}
public void setTotalpage(int totalpage) {
this.totalpage = totalpage;
this.pageindex = PageIndex.getPageIndex(pagecode, currentpage, totalpage);
}
public int getMaxresult() {
return maxresult;
}
public int getCurrentpage() {
return currentpage;
}
public void setCurrentpage(int currentpage){
this.currentpage=currentpage;
}
}
- 在项目中使用的实用hibernate 分页
- 如何在hibernate中分页获得sql的数据
- hibernate中分页的实现
- 在项目中使用Hibernate进行大数据量的性能测试,有一些总结(转贴)
- 在项目中使用Hibernate进行大数据量的性能测试,有一些总结
- 在项目中使用Hibernate进行大数据量的性能测试,有一些总结(转贴)
- 项目中正在使用的SQL分页存储过程
- 在Hibernate中使用Joda的问题
- Eclipse 在开发中使用到的快捷键很实用
- Eclipse 在开发中使用到的快捷键很实用 .
- Eclipse 在开发中使用到的快捷键很实用 .
- Eclipse 在开发中使用到的快捷键很实用
- Eclipse 在开发中使用到的快捷键很实用
- Hibernate中使用HQL进行分页查询
- 在yii中使用分页
- 项目中使用hibernate二级缓存
- 在ssh项目中hibernate的动态映射
- 在项目中集成hibernate遇到的问题(1)
- C++ 结合 Boost:40行代码读写和处理 txt 文件
- js alert confirm prompt的用法
- CentOS6 环境下的OpenVPN安装配置
- Qt中内存泄露和退出崩溃的问题
- 4.python字典和None类型
- 在项目中使用的实用hibernate 分页
- crash使用的几个链接
- css3新功能之(text-shadow实现)CSS3文字阴影效果
- 开始做dlna
- 自己写的 仿assert宏和仿 _assert()函数(附代码)
- bmob
- eclipse下配置Weblogic9./10详细配置
- 设计模式之--原型模式
- weblogic 默认端口修改