Spring+hibernate分页查询

/**
     * TOP查询
     *  @param  sql String
     *  @param  top int
     *  @return  List
      */
     public  List findTop(String sql,  int  top) {
      HibernateTemplate ht  =   this .getHibernateTemplate();
      ht.setMaxResults(top);
       return  ht.find(sql);
    }

     /**
     * 分页查询
     *  @param  sql String
     *  @param  firstRow int
     *  @param  maxRow int
     *  @return  List
      */
     public  List findPage( final  String sql, final   int  firstRow, final   int  maxRow) {
       return   this .getHibernateTemplate().executeFind( new  HibernateCallback(){
             public  Object doInHibernate(Session session)  throws  SQLException,
                    HibernateException {
               Query q  =  session.createQuery(sql);
               q.setFirstResult(firstRow);
               q.setMaxResults(maxRow);
                return  q.list();
               }
        });     
    }

模板实现分页:
public   List find(  final   String hsql,   final     int   firstRow,   final     int   maxRow)   throws         Exception {
   return  getHibernateTemplate().executeFind( new  HibernateCallback() {
     public  Object doInHibernate(Session s)  throws  HibernateException, SQLException {
           Query query  =  s.createQuery(hsql);
           query.setFirstResult(firstRow);
           query.setMaxResults(maxRow);
           List list  =  query.list();
           return  list;
           }
     });
}

AddThis Social Bookmark Button

相关文档(Relevant Entries)
Spring 的微内核与FactoryBean扩展机制
使用Spring JDBC包装基本的CRUD操作
Spring+Hibernate 复杂查询分页
hibernate+spring的一个简单分页实现
一个关于spring+hibernate的例子
Secrets of lightweight development success, Part 3: The emergence of Spring
Secrets of lightweight development success, Part 2: How to lighten up your containers
Secrets of lightweight development success, Part 1: Core principles and philosophies
Posted on April 12, 2007 11:31 PM | | | Comments (0) | | TrackBacks (0)

引用地址(TRACKBACKS)
 
TrackBack URL for this entry:
http://www.wujianrong.com/mt-tb.cgi/5111

发布评论(ADD YOUR COMMENTS)
 
感谢您参与评论;发表您的意见时请保持文章的相关性;不相关的或是单纯宣传的内容可能会被删掉。您的E-mail只是用来确认您发表的文章,不会出现在网页上。
Please keep your comments relevant to this blog entry. Email addresses are never displayed, but they are required to confirm your comments.

称呼(Name):      记住我的个人信息(Remember)
邮箱(Email):
网址(URL):
评论(Add your comments):

相关内容
广告计划