日期:2014-05-18 浏览次数:20868 次
public class ImpPageDealData extends HibernateDaoSupport implements PageDealData { //数据查询,并进行分页处理 public ArrayList getAllData(int pageNow,int pageSize,String hql){ ArrayList al=new ArrayList(); try { Query q=super.getSession().createQuery(hql); q.setFirstResult((pageNow-1)*pageSize); q.setMaxResults(pageSize); // System.out.println(q.list().size()+"======size"); al=(ArrayList)q.list(); // System.out.println(al.size()+"======size"); } catch (Exception e) { e.printStackTrace(); }finally{ this.closeConnection(); } return al; } }
------解决方案--------------------
其实不需要那么麻烦。。hibernate里面有自带的查询分页的方法
------解决方案--------------------
今天刚把SSH的分页做完
Dao层:
public List getList(final int firstResult,final int maxResult) {
final StringBuffer sb = new StringBuffer("");
String hql = "from LinkMag_o_Info";
sb.append(hql);
return getHibernateTemplate().executeFind(new HibernateCallback()
{
public Object doInHibernate(Session s) throws HibernateException, SQLException {
Query query = s.createQuery(sb.toString());
query.setFirstResult(firstResult);
query.setMaxResults(maxResult);
List list = query.list();
return list;
}
}
);
------解决方案--------------------
我是这么做的,在Dao层
public List getList(final int firstResult,final int maxResult) {
final StringBuffer sb = new StringBuffer("");
String hql = "from LinkMag_o_Info";
sb.append(hql);
return getHibernateTemplate().executeFind(new HibernateCallback()
{
public Object doInHibernate(Session s) throws HibernateException, SQLException {
Query query = s.createQuery(sb.toString());
query.setFirstResult(firstResult);
query.setMaxResults(maxResult);
List list = query.list();
return list;
}
}
);
}