`

hibernate 分页

阅读更多


三个参数,
第一个是HQL语句,如from EntryObject
第二个是从第几条记录开始
第三个是分页的页显示条数大小
find("from EntryObject",1,20);
表示查询Users 表,从第1条记录开始,共查询出20条记录

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;
           }
     });
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics