随笔-86  评论-33  文章-0  trackbacks-0
/**
     * 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();
               }
        });      
    }
posted on 2007-03-06 14:22 Derek.Guo 阅读(4560) 评论(1)  编辑  收藏 所属分类: Java

评论:
# re: Spring+hibernate分页查询 2009-03-09 11:28 | guooo
good  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
MSN:envoydada@hotmail.com QQ:34935442