public List getListForPage(final String hql, final int offset,
final int length) {
List list = getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
query.setFirstResult(offset);
query.setMaxResults(length);
List list = query.list();
return list;
}
});
return list;
}
final int length) {
List list = getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
query.setFirstResult(offset);
query.setMaxResults(length);
List list = query.list();
return list;
}
});
return list;
}
本文介绍了一种使用Hibernate实现分页查询的方法。通过定义一个公共方法`getListForPage`,可以根据提供的HQL查询语句及分页参数(起始位置和长度),执行相应的分页查询并返回结果列表。
612

被折叠的 条评论
为什么被折叠?



