Hibernate分页查询(使用HQL语言)
例:import java.util.Iterator;import java.util.List;import org.hibernate.Query;import org.hibernate.Session;import junit.framework.TestCase;public class QueryTest extends TestCase{public void testQuery(){Session session = null;try{session = HibernateUtils.getSession();session.geginTransaction();Query query = session.createQuery("from User"); //HQL查询语言query.setFirstResult(0); //从第0条开始query.setMaxResults(2); //每页2条List userList = query.list();for(Iterator iter=userList.iterator(); iter.hasNext(); ){User user = (User)iter.next();System.out.println(user.getName());}}} }