前端需要訂一page類包裝,其參數為
private Integer pageSize=10; //每頁記錄條數=10
private Integer totalCount; //總記錄條數
private Integer totalPage; //總頁數
private Integer currPage; //當前頁
private Integer startIndex; //開始索引
private List<M> list; //結果集
進行查詢的數據set進對象,在運用ModelAndView對象
ModelAndView .addObject("page",page);
將page返回前台jsp,接受成功之后在其他頁面直接引用jsp標簽<jsp:include page="/page.jsp" />就可以調用
以下為jsp頁面代碼:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!-- 最下面顯示跳轉頁面 -->
<!-- ${page.totalCount }總的記錄條數 其他的類似,與Page.java相關聯 -->
<div >
共 <i class="blue">${page.totalCount }</i>
條記錄,當前顯示第 <i class="blue">${page.currPage }
</i> 頁 / 共 <i class="blue">${page.totalPage }</i> 頁
跳轉
<input type="text" class="scinput"
style="width: 40px;height: 20px" id="currPage2" onblur="page2()"
onkeyup="this.value=this.value.replace(/\D/g,'')"
onafterpaste="this.value=this.value.replace(/\D/g,'')" /> 頁
<!-- 首頁按鈕,跳轉到首頁 -->
<p> <c:if test="${page.currPage <= 1 }"></c:if>
<a href="javascript:;" <c:if test="${page.currPage > 1 }">onclick="page1(1)"</c:if> >首頁</a>
<!-- 上頁按鈕,跳轉到上一頁 -->
<c:if test="${page.currPage <= 1 }"></c:if>
<a href="javascript:;" <c:if test="${page.currPage > 1 }">onclick="page1('${page.currPage - 1}')"</c:if> >上頁</a>
<!-- 下頁按鈕,跳轉到下一頁 -->
<c:if test="${page.currPage >= page.totalPage }"></c:if>
<a href="javascript:;" <c:if test="${page.currPage < page.totalPage }">onclick="page1('${page.currPage + 1}')"</c:if> >下頁</a>
<!-- 末頁按鈕,跳轉到最后一頁 -->
<c:if test="${page.currPage >= page.totalPage }"></c:if>
<a href="javascript:;" <c:if test="${page.currPage < page.totalPage }">onclick="page1('${page.totalPage}')"</c:if> >末頁</a>
</p>
</div>
