&&&&&&此博文參考於:http://blog.csdn.net/peng_hong_fu/article/details/53645924
css
並只運行了該大神的分頁邏輯功能。先剔出以下:html
************************ssm框架的jar包以及配置文件,在這裏就不貼了,直接上代碼.java
-----分頁的實體工具類:page.javasql
package com.topsun.util;
import java.util.List;
//分頁
public class Page<T> {
private int currPage;//當前頁
private int pageSize;//每頁顯示的記錄數
private int totalCount;//總記錄數
private int totalPage;//總頁數
private List<T> lists;//每頁顯示的數據
public Page(int currPage, int pageSize, int totalCount, int totalPage, List<T> lists) {
super();
this.currPage = currPage;
this.pageSize = pageSize;
this.totalCount = totalCount;
this.totalPage = totalPage;
this.lists = lists;
}
public Page() {
super();
}
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List<T> getLists() {
return lists;
}
public void setLists(List<T> lists) {
this.lists = lists;
}
}
---------------------------------------------------------------------------------------------------------app
-----controller 層的分頁:框架
--------service 層 方法:jsp
--------serviceImpl層 實現類:ide
--------dao層方法截圖:工具
-------mapper.xml文件裏的sql語句:ui
------list.jsp頁面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@page isELIgnored="false" %><%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>主頁</title><style type="text/css"> td{text-align: center;} .td2{text-align: right;} .table1{ border:1px solid #ddd; width:900px; } thead{ background-color:lightblue; }</style></head><body> <c:if test="${!empty requestScope.cjw}"> <table border="1" cellpadding="10" cellspacing="0" class="table1"> <thead> <tr> <td>編號</td> <td>用戶名</td> <td>年齡</td> <td>Edit</td> <td>Delete</td> </tr> </thead> <c:forEach items="${requestScope.cjw.lists}" var="u"> <tr> <th>${u.id}</th> <th>${u.name}</th> <th>${u.age}</th> <th><a href="edit?id=${u.id}">Edit</a></th> <th><a href="delete?id=${u.id}" confirm('肯定要刪除嗎')">Delete</a></th> </tr> </c:forEach> </table> </c:if><table border="0" cellspacing="0" cellpadding="0" width="900px"><tr><td class="td2"> <span>第${requestScope.cjw.currPage}/ ${requestScope.cjw.totalPage}頁</span> <span>總記錄數:${requestScope.cjw.totalCount} 每頁顯示:${requestScope.cjw.pageSize}</span> <span> <c:if test="${requestScope.pagemsg.currPage != 1}"> <a href="${pageContext.request.contextPath}/selectPage?currentPage=1">[首頁]</a> <a href="${pageContext.request.contextPath}/selectPage?currentPage=${requestScope.cjw.currPage-1}">[上一頁]</a> </c:if> <c:if test="${requestScope.cjw.currPage != requestScope.cjw.totalPage}"> <a href="${pageContext.request.contextPath}/selectPage?currentPage=${requestScope.cjw.currPage+1}">[下一頁]</a> <a href="${pageContext.request.contextPath}/selectPage?currentPage=${requestScope.cjw.totalPage}">[尾頁]</a> </c:if> </span></td></tr></table></body></html>