ssh 分页技术

jsp

<div id="feiye">
 <center>当前是第${currentPage}页,共有${totalPage}页
 <a href="yrecordinfo.action?currentPage=1" >首页</a>
 <s:if test="%{currentPage>1}"><a href="yrecordinfo.action?currentPage=${currentPage-1}" >上一页</a>
 <a href="yrecordinfo.action?currentPage=${currentPage-1}" >${currentPage-1}</a></s:if>
 <a href="yrecordinfo.action?currentPage=${currentPage}" >${currentPage}</a>
 <s:if test="%{totalPage>currentPage}"><a href="yrecordinfo.action?currentPage=${currentPage+1}" >${currentPage+1}</a>
 <a href="yrecordinfo.action?currentPage=${currentPage+1}" >下一页</a></s:if>
 <a href="yrecordinfo.action?currentPage=${totalPage}" >尾页</a></center>

 
 </div>

action

	private String num;// 查出了多少条
	private List<YRecordInfo>  recordlist;// 列表页
	private String totalPage;//总页数
	private String  currentPage ;// 当前页,
        private String pageSize="10";//一页显示多少/***
 * 分页 
 *  分析, 
 *  http://127.0.0.1:8080/aaa/main/yrecordinfo.action?currentPage=1
 *  *  1. 根据 条件  得到一个  总数, 通过计算 ,得到总页数、
 *  2. 根据 分页的  得到  自己  需要的那一页的   条数
 */
	private void feiye() {
		YRecordInfoDao   dao = new  YRecordInfoDao();
		if(currentPage==null){
			currentPage="1";
		}
 		 List<YRecordInfo>  listtemp=	dao.search(Integer.parseInt( currentPage),Integer.parseInt( pageSize));	
		
setNum(listtemp.size()+"");
setRecordlist(listtemp);
  //1. 根据 条件  得到一个  总数, 通过计算 ,得到总页数、
int totalSize = dao.search().size();// 总数量(只是根据时间查询的)

 //2. 根据 分页的  得到  自己  需要的那一页的   条数
int mod = totalSize % Integer.parseInt(pageSize);if (mod == 0) {totalPage = totalSize / Integer.parseInt(pageSize) + "";} else{totalPage = totalSize / Integer.parseInt(pageSize) + 1 + "";}setTotalPage(totalPage);}

dao

	/***
	 * **
		 * 查询多条数据 
	 * @param currentPage  //第几页
	 * @param pageSize  // //每页多少条数据  
	 * 分析:
	 *  1得到总条数,  
	 *  2 总共分几页
	 *  3根据 第几页 算出   开始索引
	 * @return
	 */
	public List<YRecordInfo>  search(int currentPage,int pageSize) {
		
		
		
		 //构建Session工具对象
		   Session s=HibernateSessionFactory.getSession();
		   //SELECT * FROM [Y_RecordInfo] where  BeginTime between '2017-04-01 00:00:00' and  '2017-05-02 23:59:59' order by PhoneId
		   
		   //HQL语句,有3个参数,参数的序号从0开始
		   String hql="from YRecordInfo   where  BeginTime between ? and  ?  order by BeginTime desc";
//			   //构建查询对象
		   Query q=s.createQuery(hql);
		   //设置查询参数
		   q.setString(0, "2017-04-21 10:06:39");
		   q.setString(1, "2017-10-21 10:06:39");
//		   q.setInteger(2, startNum);//从第几条开始
		   int startRow=(currentPage-1)*pageSize;
		   q.setFirstResult(startRow); 
		   q.setMaxResults(pageSize);
		return q.list();
	
	}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值