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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章