ssh框架中的分页查询
ssh中的分页查询是比较常用的,接下来我用代码来介绍如何实现一个分页查询
首先建立一个Model用来储存查询分页的信息
package com.haiziwang.qrlogin.utils;
import java.util.List;
public class prospage<T> {
	private int page;	// 当前页数
	private int totalCount; // 总记录数
	private int totalPage; // 总页数
	private int ererypagecount;	// 每页显示的记录数
	private List<T> list; // 每页显示数据的集合.
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getErerypagecount() {
		return ererypagecount;
	}
	public void setErerypagecount(int ererypagecount) {
		this.ererypagecount = ererypagecount;
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
	@Override
	public String toString() {
		return "prospage [page=" + page + ", totalCount=" + totalCount + ", totalPage=" + totalPage
				+ ", ererypagecount=" + ererypagecount + ", list=" + list + "]";
	}
}
这是Dao类查询的代码:
public prospage<pros> findpagebyid(int page,Integer cid){
	prospage<pros> prospage = new prospage<pros>();
	//设置当前页数
	prospage.setPage(page);
	//显示每夜记录数
	int limit=8;
	prospage.setErerypagecount(limit);
	//设置总记录数
	int totalc=0;
	totalc=findcountbycid(cid);
	prospage.setTotalCount(totalc);
	//设置总页数
	int totalpage =0;
if(totalc % limit==0){
		totalpage=totalc /  limit;
	}else{
		totalpage=totalc /  limit+1;
	}
prospage.setTotalPage(totalpage);
	//每页显示的数据
//每页从哪开始
	int a =(page-1)*limit;
	List<pros> list=getpagebycid(cid,a,limit);
	prospage.setList(list);
	return prospage;
}
//分页查询
public List<pros> getpagebycid(Integer cid, int a, int limit) {
	String hql = "select p from pros p join p.secondLei cs join cs.categroy c where c.cid = ?";
Query query = getSession().createQuery(hql).setInteger(0, cid);
List<pros> proslist = query.setFirstResult(a)  
                                   .setMaxResults(limit)  
                                   .list();  
       System.out.println("含有多少个"+proslist ); 
       if(proslist != null && proslist.size() > 0){
    	   return proslist ;
   	}
   	return null;
}
//根局一级分类查询二级分类的个数
public  int findcountbycid(Integer cid) {
	String hql="select count(*) from pros p where p.secondLei.categroy.cid=?";
	List<Long>  listcount=	getSession().createQuery(hql).setInteger(0, cid).list();
if(listcount != null && listcount.size() > 0){
		return listcount.get(0).intValue();
}
	return 0;
}
3接下来就是在Jsp显示查询信息即可
<s:iterator var ="pb" value="pagebean.list">
						<li>
									<a href="${ pageContext.request.contextPath }/pros_findpro.action?pid=<s:property value="#pb.pid"/>">
									<img src="${pageContext.request.contextPath}/<s:property value="#pb.imagepath"/>" width="170" height="170"  style="display: inline-block;">
<p style='color:green'>
											商品名字: <s:property value="#pb.pname"/>
											</p>
<p style='color:red'>
											商品价格: <s:property value="#pb.shopprice"/>
											</p>
</a>
									</li>
									</s:iterator>
span>第 <s:property value="pagebean.page"/>/<s:property value="pagebean.totalPage"/> 页</span>
				<s:if test="cid!=null">
				<a href="${ pageContext.request.contextPath }/pros_findfirstid.action?cid=<s:property value="cid"/>&page=1" class="firstPage"> </a>
				<a href="${ pageContext.request.contextPath }/pros_findfirstid.action?cid=<s:property value="cid"/>&page=<s:property value="pagebean.page-1"/>" class="previousPage"> </a>
<s:iterator var="i" begin="1" end="pagebean.totalPage">
<a href="${ pageContext.request.contextPath }/pros_findfirstid.action?cid=<s:property value="cid"/>&page=<s:property value="#i"/>"><s:property value="#i"/></a>
</s:iterator>
				<a class="nextPage" href="${ pageContext.request.contextPath }/pros_findfirstid.action?cid=<s:property value="cid"/>&page=<s:property value="pagebean.page+1"/>"> </a>
				<a class="lastPage" href="${ pageContext.request.contextPath }/pros_findfirstid.action?cid=<s:property value="cid"/>&page=<s:property value="pagebean.totalPage"/>"> </a>
			</s:if>
			<s:if test="csid!=null">
<a href="${ pageContext.request.contextPath }/pros_findcsid.action?csid=<s:property value="csid"/>&page=1" class="firstPage"> </a>
				<a href="${ pageContext.request.contextPath }/pros_findcsid.action?csid=<s:property value="csid"/>&page=<s:property value="pagebean.page-1"/>" class="previousPage"> </a>
<s:iterator var="i" begin="1" end="pagebean.totalPage">
<a href="${ pageContext.request.contextPath }/pros_findcsid.action?csid=<s:property value="csid"/>&page=<s:property value="#i"/>"><s:property value="#i"/></a>
</s:iterator>
				<a class="nextPage" href="${ pageContext.request.contextPath }/pros_findcsid.action?csid=<s:property value="csid"/>&page=<s:property value="pagebean.page+1"/>"> </a>
				<a class="lastPage" href="${ pageContext.request.contextPath }/pros_findcsid.action?csid=<s:property value="csid"/>&page=<s:property value="pagebean.totalPage"/>"> </a>
</s:if>
ssh框架中的分页查询的更多相关文章
- SSH框架的多表查询和增删查改 (方法一)中
		
原创作品,允许转载,转载时请务必标明作者信息和声明本文章==>http://www.cnblogs.com/zhu520/p/7774144.html 这边文章是接的刚刚前一遍的基础上敲的 ...
 - SSH框架的多表查询和增删查改 (方法一)上
		
原创作品,允许转载,转载时请务必标明作者信息和声明本文章==> http://www.cnblogs.com/zhu520/p/7772823.html 因为最近在做Android 练习的 ...
 - 在SSH框架中使用Spring的好处(转)
		
以下是我总结下今天笔试中SSh中的总结: 在SSH框架中spring充当了管理容器的角色.我们都知道Hibernate用来做持久层,因为它将JDBC做了一个良好的封装,程序员在与数据库进行交互时可以不 ...
 - mongo中的分页查询
		
/** * @param $uid * @param $app_id * @param $start_time * @param $end_time * @param $start_page * @p ...
 - 在SSH框架中,如何得到POST请求的URL和参数列表
		
在做项目的API通知接口的时候,发现在SSH框架中无法获取到对方服务器发来的异步通知信息.最后排查到的原因可能是struts2对HttpServletRequest进行了二次处理,那么该如何拿到pos ...
 - SSH框架中配置log4j的方法
		
SSH框架中使用log4j的方便之处 1. 动态的改变记录级别和策略,即修改log4j.properties,不需要重启Web应用,这需要在web.xml中设置一下.2. 把log文件定在 /WEB- ...
 - SSH框架中hibernate 出现 user is not mapped 问题
		
SSH框架中hibernate 出现 user is not mapped 问题 在做SSH框架整合时,在进行DAO操作时.这里就只调用了chekUser()方法.运行时报 user is ...
 - django-drf框架中排序和查询组件
		
0910自我总结 django-drf框架中排序和查询组件 一查询相关 1.模糊查询 1.导入模块组件 from rest_framework.filters import SearchFilter ...
 - java使用插件pagehelper在mybatis中实现分页查询
		
摘要: com.github.pagehelper.PageHelper是一款好用的开源免费的Mybatis第三方物理分页插件 PageHelper是国内牛人的一个开源项目,有兴趣的可以去看源码,都有 ...
 
随机推荐
- Android系统分析之Audio音频流, 音频策略, 输出设备之间的关系
			
音频流, 音频策略, 输出设备之间的关系 只针对 AudioManager.STREAM_VOICE_CALL 音频流类型进行分析 涉及到的类: hardware/libhardware_legacy ...
 - Elasticsearch中文文档,内容不全
			
注意 内容不全,这是观看中文文档进行操作的 文档地址 旧版中文文档,部分内容过期 https://www.elastic.co/guide/cn/elasticsearch/guide/current ...
 - Spark报错java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
			
Spark 读取 JSON 文件时运行报错 java.io.IOException: Could not locate executable null\bin\winutils.exe in the ...
 - Hybrid APP架构设计
			
通讯 作为一种跨语言开发模式,通讯层是Hybrid架构首先应该考虑和设计的,往后所有的逻辑都是基于通讯层展开. Native(以Android为例)和H5通讯,基本原理: Android调用H5:通过 ...
 - 从一道索引数据结构面试题看B树、B+树
			
题目1: Mysql数据库用过吧?l里面的索引是基于什么数据结构. 答:主要是基于Hash表和B+树 题目2: 很好请你说一下B+树的实现细节是什么样的?B-树和B+树有什么区别?联合索引在B+树中如 ...
 - hdu 4747 线段树/DP
			
先是线段树 可以知道mex(i,i),mex(i,i+1)到mex(i,n)是递增的. 首先很容易求得mex(1,1),mex(1,2)......mex(1,n) 因为上述n个数是递增的. 然后使用 ...
 - iOS中为控件设置颜色渐变和透明度渐变
			
项目中用到地图设置渐变色,查找资料找到两种方法:一种设置颜色,一种设置透明度: //为颜色设置渐变效果: UIView *view = [[UIView alloc] initWithFrame:CG ...
 - centos后台运行程序
			
putty等软件运行,python程序:python p.py 只要一关闭putty, 程序就结束.如何让退出终端或关闭终端电脑,还能让程序在服务器后台运行Python. 关键的命令:nohup ...
 - 当心JavaScript奇葩的逗号表达式
			
看看下面的代码输出什么? let a = 2; switch (a) { case (3, 2, 5): console.log(1); break case (2, 3, 4): console.l ...
 - electron-vue 升级 从2.x升级到4.x的坑
			
子窗口 2.x modal为true let messageRightMenu = new BrowserWindow({ // height: 170, // width: 70, useConte ...