📄 pagehandleimpl.java
字号:
package com.cucu.tapestry.dao.impl;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.type.Type;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate.HibernateCallback;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.cucu.tapestry.dao.PageHandle;
/**
* Hibernate分页实现类
*
* @author 绝情酷哥
* @version 1.0
*/
public class PageHandleImpl extends HibernateDaoSupport implements PageHandle {
/**
* @param hql
* @param pos
* @param size
* @return List
* @throws DataAccessException
*/
public List getPageItems(final String hql, final int pos, final int size)
throws DataAccessException {
Object[] objs = null;
Type[] types = null;
return getPageItems(hql, objs, types, pos, size);
}
/**
* @param hql
* @param obj
* @param type
* @param pos
* @param size
* @return List
* @throws DataAccessException
*/
public List getPageItems(
final String hql,
final Object obj,
final Type type,
final int pos,
final int size)
throws DataAccessException {
Object[] objs = new Object[]{obj};
Type[] types = new Type[]{type};
return getPageItems(hql, objs, types, pos, size);
}
/**
*
*
* @param hql
* @param objs
* @param types
* @param size
* @return List
* @throws DataAccessException
*/
public List getPageItems(
final String hql,
final Object[] objs,
final Type[] types,
final int pos,
final int size)
throws DataAccessException {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
Query query = getHibernateTemplate().createQuery(session, hql);
if (objs != null) {
int len = objs.length;
// 参数绑定
for (int i = 0; i < len; i++) {
query.setParameter(i, objs[i], types[i]);
}
}
query.setFirstResult(pos);
query.setMaxResults(size);
return query.list();
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -