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

          評論:
          # re: Spring+hibernate分頁查詢 2009-03-09 11:28 | guooo
          good  回復  更多評論
            
          MSN:envoydada@hotmail.com QQ:34935442
          主站蜘蛛池模板: 云林县| 绥化市| 岑巩县| 阿巴嘎旗| 岳普湖县| 海伦市| 南澳县| 剑川县| 调兵山市| 扶沟县| 聂荣县| 临猗县| 泰顺县| 邹城市| 孟州市| 漳浦县| 绍兴县| 阳信县| 浦江县| 长子县| 仁布县| 莱芜市| 扬州市| 中卫市| 监利县| 绥宁县| 辽阳市| 林周县| 庐江县| 清镇市| 太仓市| 那坡县| 凤山市| 克东县| 竹山县| 临湘市| 揭西县| 八宿县| 六盘水市| 纳雍县| 雷波县|