九月未央

          導(dǎo)航

          <2008年10月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          留言簿

          文章分類

          文章檔案

          閱讀排行榜

          評論排行榜

          統(tǒng)計

          最新評論

          一個很好的hibernate分頁的例子

          此工程是hibernate和struts完美應(yīng)用和分頁演示示例。下載

          特點:
          一、使用MS SERVER 2000的pubs數(shù)據(jù)庫,并寫了演示用的數(shù)據(jù)庫腳本
          二、應(yīng)用hibernate和struts結(jié)合開發(fā),完美的演示了數(shù)據(jù)的增、刪、改、查。
          三、演示了數(shù)據(jù)查詢的分頁功能(較簡單)。

          在這里,我把主要的代碼寫下來:
          public class test {
              
          /**
               * 
               * @TODO
               * 
          @param hql
               * 
          @param pageNum 第幾頁?
               * 
          @param pageSize 每頁條數(shù)
               * 
          @return list;
               * @蔣祖兵 2007-8-9 下午01:27:08
               
          */

              
          public List pagination(String hql, int pageNum, int pageSize) {
                  
          int numBegin = 0;
                  
          if(pageNum<1)
                  
          {
                      numBegin 
          = 0;
                  }

                  
          else
                  
          {
                      numBegin 
          = (pageNum - 1)*pageSize;
                  }

                  List retList 
          = new ArrayList();
                  Session session 
          = SessionFactory.getSession(); 
                  
          try {
                      Query query 
          = session.createQuery(hql);
                      query.setFirstResult(numBegin);
                      query.setMaxResults(pageSize);
                      retList 
          = query.list();
                      
          return retList;
                  }
           catch (HibernateException e) {
                      e.printStackTrace();
                  }

          /*        finally{
                      try {
                          session.close();
                      } catch (HibernateException e) {
                          e.printStackTrace();
                      }
                  }
          */

                  
          return retList;
              }

              
          public static void  main(String args[]){
                  test t 
          =  new test();
                  String hql 
          = "from Test ";
                  List list 
          = t.pagination(hql, 18);
                  
          for(int i =0 ; i<list.size();i++){
                      Test t
          = (Test )list.get(i);
                      
          //System.out.println(t.getId());
                  }

              }

          }

          posted on 2008-03-29 00:30 yongan 閱讀(1364) 評論(1)  編輯  收藏 所屬分類: hibernate和struts

          評論

          # re: 一個很好的hibernate分頁的例子 2008-10-29 11:44 齊納爾多

          這個例子很好呀 謝謝 正要用  回復(fù)  更多評論   


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 尉氏县| 鄂州市| 新密市| 寿光市| 孝感市| 德令哈市| 肥乡县| 清丰县| 冷水江市| 和静县| 孟村| 广昌县| 虹口区| 黎城县| 通辽市| 博乐市| 拜城县| 萨嘎县| 慈利县| 石楼县| 万源市| 苍山县| 平阳县| 丽江市| 应用必备| 潜江市| 陵水| 长汀县| 张掖市| 临西县| 常山县| 南召县| 醴陵市| 那坡县| 尼木县| 遂宁市| 广宁县| 东安县| 漳州市| 太谷县| 酒泉市|