java中的分頁技術 查詢分頁

JSp頁面添加

<td colspan="5"align="right">

        <div class="pages">

           ${requestScope.pageBar}

           <divclass="cr"></div>  

        </div>

 </td>

Java代碼

Action中: list=this.queryPage(sql);    //根據生sql語句進行分頁查詢

||  調用下面的方法

public ListqueryPage(String sql) {

       Paging pageing = new Paging();

       int count =queryCountBySql(sql);  //根據sql獲取總的分頁數目

       pageing.init(null, 10, Long.valueOf(count), 1);

       returnqueryObjectBySize(sql,pageing.getStart(),10);//分頁查詢

}

 

 

//獲取總的分頁數

    publicintqueryCountBySql(Stringsql) {

       try {

           List list = this.oraJDBCTemplate.queryForList(sql);

           if(null != list && list.size()>0){

              return list.size();

           }

       } catch (Exception e) {

            e.printStackTrace();

       }

       return 0;

}

     //根據SQL語句和起始頁、終止頁分頁

    publicListqueryObjectBySize(String sql, int start,int end) {

       List list = null;

       try{

list = this.oraJDBCTemplate.queryForList("select * from (select a.*, rownum rownum_  from ( "+sql+") a "

                +" where rownum <= "+(start+end)

                +") where rownum_ > "+start);

       }catch(Exception e){

           e.printStackTrace();

       }

          return list;

}

發佈了37 篇原創文章 · 獲贊 13 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章