使用ssh完成分页
2017-12-05 21:05
316 查看
封装page
public class pageBean {
//当前页
private int currentPage;
//总页数
private int pageCount;
//每页显示的条数
private int pageSize;
//总记录数
private int pageSum;
//开始的索引
private int beginIndex;
//结束的索引
private int endIndex;
//页面的信息
private List recordList;
public pageBean() {
super();
// TODO Auto-generated constructor stub
}
public pageBean(int currentPage,List recordList,int pageSize,int pageSum ) {
this.currentPage=currentPage;
this.recordList=recordList;
this.pageSum=pageSum;
this.pageSize=pageSize;
//总页数的计算方法
pageCount = (pageSum+pageSize-1)/pageSize;
//判断起点和结束点,如果总数不到十条就全部显示
if (pageCount<10) {
this.beginIndex=1;
this.endIndex=pageCount;
//否则显示以下的信息
}else {
//开始页显示当前页前面的前4页
this.beginIndex=this.currentPage-4;
//开始页显示当前页前面的后5页
this.endIndex=this.currentPage+5;
//如何左面的开始位置小于1 那他就是1,右面就是10
if (this.beginIndex<1) {
this.beginIndex=1;
this.endIndex=10;
}
//如何右面的开始位置大于总页数
if (this.endIndex>pageCount) {
this.beginIndex=pageCount-9;
this.endIndex=pageCount;
}
}
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getPageSum() {
return pageSum;
}
public void setPageSum(int pageSum) {
this.pageSum = pageSum;
}
public int getBeginIndex() {
return beginIndex;
}
public void setBeginIndex(int beginIndex) {
this.beginIndex = beginIndex;
}
public int getEndIndex() {
return endIndex;
}
public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}
public List getRecordList() {
return recordList;
}
public void setRecordList(List recordList) {
this.recordList = recordList;
}
}
dao的计算方式
public pageBean getPageBean(int currentPage, Theme theme) {
// TODO Auto-generated method stub
int pageSize=2;
//在第几页开始查找
int firstResult =(currentPage-1)*pageSize;
//根据查询条件查询
String hql = "from Reply r where r.theme=? order by r.postTime asc";
List recordList = getSession().createQuery(hql).setParameter(0, theme).setFirstResult(firstResult).setMaxResults(pageSize).list();
//查找总记录数
hql="select count(*) from Reply r where r.theme=? ";
Long count =(Long) getSession().createQuery(hql).setParameter(0, theme).uniqueResult();
return new pageBean(currentPage, recordList, pageSize, count.intValue());
}
实现效果
public class pageBean {
//当前页
private int currentPage;
//总页数
private int pageCount;
//每页显示的条数
private int pageSize;
//总记录数
private int pageSum;
//开始的索引
private int beginIndex;
//结束的索引
private int endIndex;
//页面的信息
private List recordList;
public pageBean() {
super();
// TODO Auto-generated constructor stub
}
public pageBean(int currentPage,List recordList,int pageSize,int pageSum ) {
this.currentPage=currentPage;
this.recordList=recordList;
this.pageSum=pageSum;
this.pageSize=pageSize;
//总页数的计算方法
pageCount = (pageSum+pageSize-1)/pageSize;
//判断起点和结束点,如果总数不到十条就全部显示
if (pageCount<10) {
this.beginIndex=1;
this.endIndex=pageCount;
//否则显示以下的信息
}else {
//开始页显示当前页前面的前4页
this.beginIndex=this.currentPage-4;
//开始页显示当前页前面的后5页
this.endIndex=this.currentPage+5;
//如何左面的开始位置小于1 那他就是1,右面就是10
if (this.beginIndex<1) {
this.beginIndex=1;
this.endIndex=10;
}
//如何右面的开始位置大于总页数
if (this.endIndex>pageCount) {
this.beginIndex=pageCount-9;
this.endIndex=pageCount;
}
}
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getPageSum() {
return pageSum;
}
public void setPageSum(int pageSum) {
this.pageSum = pageSum;
}
public int getBeginIndex() {
return beginIndex;
}
public void setBeginIndex(int beginIndex) {
this.beginIndex = beginIndex;
}
public int getEndIndex() {
return endIndex;
}
public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}
public List getRecordList() {
return recordList;
}
public void setRecordList(List recordList) {
this.recordList = recordList;
}
}
dao的计算方式
public pageBean getPageBean(int currentPage, Theme theme) {
// TODO Auto-generated method stub
int pageSize=2;
//在第几页开始查找
int firstResult =(currentPage-1)*pageSize;
//根据查询条件查询
String hql = "from Reply r where r.theme=? order by r.postTime asc";
List recordList = getSession().createQuery(hql).setParameter(0, theme).setFirstResult(firstResult).setMaxResults(pageSize).list();
//查找总记录数
hql="select count(*) from Reply r where r.theme=? ";
Long count =(Long) getSession().createQuery(hql).setParameter(0, theme).uniqueResult();
return new pageBean(currentPage, recordList, pageSize, count.intValue());
}
实现效果
相关文章推荐
- mac下如何使用ssh-copy-id完成ssh的公钥认证登录
- 【SSH网上商城项目实战05】完成数据库的级联查询和分页
- 使用AspNetPager与GridView完成分页
- Displaytag使用与应用displaytag完成大数据量分页显示的例子
- 使用jenkins完成参数化构建-集成git和ssh-未完待续
- SSH网上商城之使用ajax完成用户名是否存在异步校验
- ssh整合问题总结--使用HibernateTemplate实现数据分页展示
- 【SSH网上商城项目实战05】完成数据库的级联查询和分页
- 使用AspNetPager与GridView完成分页
- 下拉框自动完成(autocomplete)带有分页功能SutaraLumpur-jquery.ajaxComboBox.js的使用
- 下拉框自动完成(autocomplete)带有分页功能SutaraLumpur-jquery.ajaxComboBox.js的使用
- ssh整合问题总结--使用HibernateTemplate实现数据分页展示
- 使用AspNetPager与GridView完成分页
- 数据库分页的封装类编写和在SSH中的使用
- 模拟网易邮箱实现全选,全不的功能/使用DataList实现 加入购物车,编辑,删除,更新,取消功能。/试完成Datalist使用存储过程来分页
- 【SSH网上商城项目实战05】完成数据库的级联查询和分页
- SSH网上商城---使用ajax完成用户名是否存在异步校验
- 使用分页模板完成,显示上一页,下一页,第一页,最后一页,和当前第x页,共y页 。
- 使用AspNetPager与GridView完成分页
- 使用Ajax完成用户名异步校验--【SSH】