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

          評論:
          # re: Spring+hibernate分頁查詢 2009-03-09 11:28 | guooo
          good  回復  更多評論
            
          MSN:envoydada@hotmail.com QQ:34935442
          主站蜘蛛池模板: 澎湖县| 信宜市| 湾仔区| 台中县| 梧州市| 奉贤区| 同德县| 襄汾县| 宁陵县| 浏阳市| 资阳市| 贞丰县| 韶关市| 民县| 武城县| 宿迁市| 贵溪市| 肥东县| 怀安县| 若尔盖县| 汶川县| 华蓥市| 临安市| 洪洞县| 太保市| 资兴市| 乌拉特中旗| 克什克腾旗| 河间市| 仁化县| 礼泉县| 嘉兴市| 双桥区| 民乐县| 通山县| 丰顺县| 潼南县| 南溪县| 共和县| 措美县| 达日县|