getHibernateTemplate() 分页查询

分页查询:
final String hql = "from TransportOrders t where t.carriageUserId!=null order by t.orderId desc";
getHibernateTemplate().executeFind(
					new HibernateCallback() {
						public Object doInHibernate(Session session)
								throws HibernateException, SQLException {
							Query query = session.createQuery(hql);
							query.setFirstResult((page - 1) * pageSize);
							query.setMaxResults(pageSize);
							List list = query.list();
							return list;
						}
					});

查询总条数
Long num=(Long) getHibernateTemplate().find("select count(*) from TransportOrders t where t.carriageUserId!=null").listIterator().next();
   
count=num.intValue();

 

你可能感兴趣的:(SSH,java)