Pager pager = new Pager(); int totalRows = service.countTotalRows();//根据条件查询出总共行数 pager.init(totalRows, curpageInt, perpage); pager.setPageUrl(url);//url是查询条件,url="/subadminPoster.do?act=searchRev&curpage" List list = service.getData();//根据条件查询list pager.setData(list); request.setAttribute("pager", pager);
3.hibernate配合pager类的使用
public List getDataList(final String hql, final Integer curpage, final Integer perpage) throws Exception { HibernateTemplate ht = new HibernateTemplate(this.getSessionFactory()); return (List) ht.execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query query = session.createQuery(hql); query.setFirstResult((curpage - 1) * perpage); query.setMaxResults(perpage); List result = query.list(); return result; } }); }