hibernate的分页查询有个好处,就是不用管数据库方言。比如db2的分页查询很麻烦,但是用hibernate的方式,就完全不用管这些了
/* 使用HQL分页查询Customer信息 */ public static List<Customer> listPageCustomer_HQL(int pageNo, int perPageNum) { Session session = HibernateUtils.getSession(); String hql = "from Customer c order by c.userName desc"; Query query = session.createQuery(hql); query.setFirstResult((pageNo - 1) * perPageNum); query.setMaxResults(perPageNum); List<Customer> list = query.list(); return list; }
时间: 2024-10-05 14:59:04