前端須要訂一page類包裝,其參數爲javascript
private Integer pageSize=10; //每頁記錄條數=10
private Integer totalCount; //總記錄條數
private Integer totalPage; //總頁數
private Integer currPage; //當前頁
private Integer startIndex; //開始索引
private List<M> list; //結果集html
進行查詢的數據set進對象,在運用ModelAndView對象前端
ModelAndView .addObject("page",page);java
將page返回前臺jsp,接受成功以後在其餘頁面直接引用jsp標籤<jsp:include page="/page.jsp" />就能夠調用jsp
如下爲jsp頁面代碼:this
<%@ 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>