Hibernate自带的分页功能代码示例

{
  ...
  Session session = HibernateUtil.currentSession();
  Transaction tx = session.beginTransaction();
  Query q = session.createQuery("from Data");
 
  q.setFirstResult(0); //查询记录的起始位置
  q.setMaxResults(8);  //查询记录数  
 

  tx.commit();
  List list = q.list();
  Iterator it = list.iterator();
  ...
  session.close();

  return mapping.findForward("SUCCESS");
}

你可能感兴趣的:(Hibernate)