隨筆-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 閱讀(4606) 評論(1)  編輯  收藏 所屬分類: Java

          評論:
          # re: Spring+hibernate分頁查詢 2009-03-09 11:28 | guooo
          good  回復  更多評論
            
          MSN:envoydada@hotmail.com QQ:34935442
          主站蜘蛛池模板: 兴国县| 石城县| 长兴县| 读书| 临清市| 海伦市| 金堂县| 中阳县| 京山县| 巫山县| 安宁市| 五峰| 乌拉特前旗| 如东县| 桐庐县| 华亭县| 浑源县| 交城县| 共和县| 东明县| 南丹县| 雷州市| 凉城县| 兴城市| 锦州市| 荥经县| 舟山市| 天峻县| 德格县| 大洼县| 溆浦县| 疏附县| 名山县| 山东| 泗水县| 蒲城县| 平泉县| 凤城市| 宁国市| 宜丰县| 双牌县|