分页

原创 2012年03月21日 16:24:12
 

StringBuffer hql = new StringBuffer("from  TblLegalHoliday  WHERE  1=1");
  StringBuffer countHql = new StringBuffer(
    "select count(*) from  TblLegalHoliday  WHERE  1=1");

  if (holidayDateStart != null && holidayDateEnd != null) {
   hql.append(" and holidayDate>=? and holidayDate <=?");
   countHql.append(" and holidayDate>=? and holidayDate <=?");
  }
  if (!StringUtils.isEmpty(dateName)) {
   hql.append(" and dateName like :dateName");
   countHql.append(" and dateName like :dateName");
  }
  Session session = getHibernateTemplate().getSessionFactory()
    .getCurrentSession();
  Query query = session.createQuery(hql.toString());
  Query query2 = session.createQuery(countHql.toString());
  if (holidayDateStart != null && holidayDateEnd != null) {
   query.setDate(0, DateUtils.parserStringToDate(holidayDateStart));
   query.setDate(1, DateUtils.parserStringToDate(holidayDateEnd));

   query2.setDate(0, DateUtils.parserStringToDate(holidayDateStart));
   query2.setDate(1, DateUtils.parserStringToDate(holidayDateEnd));
  }
  if (!StringUtils.isEmpty(dateName)) {
   query.setString("dateName", "%" + dateName + "%");
   query2.setString("dateName", "%" + dateName + "%");
  }
  query.setFirstResult(startRow);
  query.setMaxResults(pageSize);

  pageBean.setList(query.list());

  query.setFirstResult(startRow);
  query.setMaxResults(pageSize);
  int totalPage = ((Long) query2.uniqueResult()).intValue();
  int pageIndex = (startRow / pageSize) + 1;

  pageBean.setCurrentPage(pageIndex);

  pageBean.setPageSize(pageSize);
  int pageCount = (int) ((totalPage - 1 + pageSize) / pageSize);
  if (pageCount > 0 && pageIndex > pageCount) {
   pageIndex = pageCount;
  }
  pageBean.setTotalPage(pageCount);
  System.out.println("***************** totalPage:" + totalPage);
  pageBean.setAllRow(totalPage);

版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)