ITeye博客

分页方法

virusfu · 2011-03-10 11:16 · hibernate · 企业架构 · Markdown

给你个例子,我现在做的工程也是s2+h的。
public List executefind(final String sql, final int startNum, final int maxNum, final Map<String, Object> maps){
  List list = null;
  list = (List)getHibernateTemplate().executeFind(new HibernateCallback(){
   @Override
   public Object doInHibernate(Session session)
     throws HibernateException, SQLException {
     final Query query = session.createQuery(sql);
     final Set<String> mapKeys = maps.keySet();
     for(final String mapKey : mapKeys){
      query.setParameter(mapKey, maps.get(mapKey));
     }
     if(maxNum > 0){
      query.setFirstResult(startNum);
      query.setMaxResults(maxNum);
     }
     
    return query.list();
   }
   
  });
  return list;
 }

里面的if(maxNum > 0)是我的一个业务需要,你可以忽略不计。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。