Spring Hibernate 模板实现分页

来源:互联网 发布:智慧城市 知乎 编辑:程序博客网 时间:2024/05/06 21:03

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; 
           } 
     }); 
}