HibernateDaoSupportに基づくページ付け

Pagination Based Hibernatedaosupport

HibernateDaoSupportに基づく3つのページング制御方法

package com.lbx.chat.paging import java.sql.SQLException import java.util.List import org.hibernate.HibernateException import org.hibernate.Query import org.hibernate.Session import org.springframework.orm.hibernate3.HibernateCallback import org.springframework.orm.hibernate3.HibernateTemplate import org.springframework.orm.hibernate3.support.HibernateDaoSupport /** * Three paging control methods based on HibernateDaoSupport * @author Administrator * */ public class PageDaoHibernateDaoSupport extends HibernateDaoSupport { /** * Use HQL statement for paging query operation *offset index of the first record * pageSize number of records to display per page * @return all records for the current page */ public List findByPage(final String hql, final int offset, final int pageSize){ List list = getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { List result = session.createQuery(hql).setFirstResult(offset) .setMaxResults(pageSize) .list() return result } }) return list } /** * Use HQL statement for paging query operation * value If HQL has a parameter that needs to be passed, then value is the passed parameter. *offset index of the first record * pageSize number of records to display per page * @return all records for the current page */ public List findByPage(final String hql, final Object value, final int offset, final int pageSize){ //System.out.println('PageDaoHibernate.findByPage()') List list = getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { List result = session.createQuery(hql).setFirstResult(offset) .setParameter(0, value) .setMaxResults(pageSize) .list() return result } }) return list } /** * Use HQL statement for paging query operation * values ​​If HQL has multiple parameters that need to be passed, then values ​​is the argument array of the passed person. *offset index of the first record * pageSize number of records to display per page * @return all records for the current page */ public List findByPage(final String hql, final Object[] values, final int offset, final int pageSize){ List list = getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(hql) for (int i = 0 i