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;
}