在这里,我把主要的代码写下来: public class test { /** */ /** * * @TODO * @param hql * @param pageNum 第几页? * @param pageSize 每页条数 * @return list; * @蒋祖兵 2007-8-9 下午01:27:08 */ public List pagination(String hql, int pageNum, int pageSize) { int numBegin = 0 ; if (pageNum < 1 ) { numBegin = 0 ; } else { numBegin = (pageNum - 1 ) * pageSize; } List retList = new ArrayList(); Session session = SessionFactory.getSession(); try { Query query = session.createQuery(hql); query.setFirstResult(numBegin); query.setMaxResults(pageSize); retList = query.list(); return retList; } catch (HibernateException e) { e.printStackTrace(); } /**/ /* finally{ try { session.close(); } catch (HibernateException e) { e.printStackTrace(); } } */ return retList; } public static void main(String args[]) { test t = new test(); String hql = " from Test " ; List list = t.pagination(hql, 1 , 8 ); for ( int i = 0 ; i < list.size();i ++ ) { Test t = (Test )list.get(i); // System.out.println(t.getId()); } } }