ssm项目-实现分页查询
程序员文章站
2024-03-14 20:38:17
...
实现分页查询功能
1.contoller层:
2.service层:
3.serviceImpl:
4.dao层
5.sql映射文件
PageSupport类代码:
package cn.smbms.tools;
public class PageSupport {
//当前页码-来自于用户输入
private int currentPageNo = 1;
//总数量(表)
private int totalCount = 0;
//页面容量
private int pageSize = 0;
//总页数-totalCount/pageSize(+1)
private int totalPageCount = 1;
public int getCurrentPageNo() {
return currentPageNo;
}
public void setCurrentPageNo(int currentPageNo) {
if(currentPageNo > 0){
this.currentPageNo = currentPageNo;
}
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
if(totalCount > 0){
this.totalCount = totalCount;
//设置总页数
this.setTotalPageCountByRs();
}
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
if(pageSize > 0){
this.pageSize = pageSize;
}
}
public int getTotalPageCount() {
return totalPageCount;
}
public void setTotalPageCount(int totalPageCount) {
this.totalPageCount = totalPageCount;
}
public void setTotalPageCountByRs(){
if(this.totalCount % this.pageSize == 0){
this.totalPageCount = this.totalCount / this.pageSize;
}else if(this.totalCount % this.pageSize > 0){
this.totalPageCount = this.totalCount / this.pageSize +1;
}else{
this.totalPageCount = 0;
}
}
}
jsp部分代码:
<%--引入(导入)rollpage.jsp文件--%>
<input type="hidden" id="totalPageCount" value="${pageSupport.totalPageCount}"/>
<input type="hidden" name="pageIndex" value="1"/>
<%--相对路径--%>
<c:import url="../common/rollpage.jsp">
<c:param name="totalCount" value="${pageSupport.totalCount}"/>
<c:param name="currentPageNo" value="${pageSupport.currentPageNo}"/>
<c:param name="totalPageCount" value="${pageSupport.totalPageCount}"/>
</c:import>
</div>
rollpage.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<div class="page-bar">
<ul class="page-num-ul clearfix">
<li>共${param.totalCount }条记录 ${param.currentPageNo }/${param.totalPageCount }页</li>
<c:if test="${param.currentPageNo > 1}">
<a href="javascript:page_nav(document.forms[0],1);">首页</a>
<a href="javascript:page_nav(document.forms[0],${param.currentPageNo-1})">上一页</a>
</c:if>
<c:if test="${param.currentPageNo < param.totalPageCount }">
<a href="javascript:page_nav(document.forms[0],${param.currentPageNo+1 });">下一页</a>
<a href="javascript:page_nav(document.forms[0],${param.totalPageCount });">最后一页</a>
</c:if>
</ul>
<span class="page-go-form"><label>跳转至</label>
<input type="text" name="inputPage" id="inputPage" class="page-key" />页
<button type="button" class="page-btn" onClick='jump_to(document.forms[0],document.getElementById("inputPage").value)'>GO</button>
</span>
</div> <%--class="page-bar" end--%>
<script type="text/javascript" src="${pageContext.request.contextPath }/statics/js/rollpage.js"></script>
上一篇: 三级联动菜单联动 (Jquery版)