spring mvc jstl分页

分页样式

/**分页样式**/
.pagination{height:30px;vertical-align:middle;margin:5px 10px 0;}
.pagination a{display:inline-block;margin-right:5px;width:25px;height:25px;line-height:25px;border:1px solid #ccc;text-align:center;text-decoration:none;color:#555;font-size:14px;overflow:hidden}
.pagination a:hover{background-color:#FFEDE1;text-decoration:none;font-weight:700;border-color:#FD6D01}
.pagination .current{display:inline-block;margin-right:5px;width:25px;height:25px;line-height:25px;border:1px solid #FD6D01;text-align:center;color:#555;font-size:14px;overflow:hidden;background-color:#FFEDE1;font-weight:700}
.pagination a.pagenum{width:52px;height:25px}
.pagination span{margin-right:5px;width:25px;height:25px;line-height:25px;display:inline-block;font-family:Tahoma,SimSun,Arial;font-size:12px;text-align:center;vertical-align:top;}
.pagination .prev,.pagination .next{display:inline-block;margin-right:5px;width:50px;height:25px;line-height:25px;border:1px solid #ccc;text-align:center;color:#999;font-size:14px;overflow:hidden}
.pagination .pagejump{width:auto;color:#666;vertical-align:top;padding:0 5px;}
.pagination .pagejump input{width:30px;height:20px;text-align:center;font-family:Tahoma,SimSun,Arial;color:#000;border:1px solid #999;margin:0 5px}
.pagination .pagejump button{width:50px;height:25px;cursor:pointer;border:1px solid #ccc;margin:0 0 0 5px}



pages.jsp

<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!--接收参数total,总记录数-->
<c:set var="total" value="${param.total}"/>
<!--接收参数total,总页数-->
<c:set var="pagesCount" value="${param.pagesCount}"/>
<!--接收参数pageSize,每页最多显示的记录数-->
<c:set var="pageSize" value="${param.pageSize}"/>
<!--接收参数url,当前页-->
<c:set var="pageIndex" value="${param.pageIndex}"/>
<!--接收参数url,要分页的页面URL-->
<c:set var="url" value="${param.pageUrl}"/>
<!--接收参数searchText-->
<c:set var="keywords" value="${param.keywords}"/>

<script type="text/javascript">
function onSubmit(){
    var re = /^[1-9][0-9]*$/;
    if(!re.test($("#pageNum1").val())){
        $("#pageNum1").val(1);
    }
    if(Number($("#pageNum1").val())>Number("${pagesCount}")){
        $("#pageNum1").val("${pagesCount}");
    }
    $("#pageIndex_p").val($("#pageNum1").val());
    $("#pagination").submit();
}


function page(pageIndex){
    $("#pageIndex_p").val(pageIndex);
    $("#pagination").submit();
}
</script>
<c:if test="${pagesCount>0}">
<div class="pagination">
<form action="${url}" method="post" id="pagination">
<input type="hidden" name="pageSize" value="${pageSize}"/>
<input type="hidden" name="pageIndex" id="pageIndex_p"/>
<input type="hidden" name="searchText" value="${keywords}"/>
<c:if test="${fn:indexOf(url,'?')==-1}">
<c:choose>
<c:when test="${pageIndex==1}">
<span class="prev">首页</span>
<span class="prev">上一页</span>
</c:when>
<c:otherwise>
<a href="#" onClick="page('1')" class="pagenum" >首页</a>
<a href="#" onClick="page('${pageIndex-1}')" class="pagenum" >上一页</a>
</c:otherwise>
</c:choose>
<c:if test="${pageIndex-3>0}">
<a href="#" onClick="page('${pageIndex-3}')">${pageIndex-3}</a>
</c:if>
<c:if test="${pageIndex-2>0}">
<a href="#" onClick="page('${pageIndex-2}')">${pageIndex-2}</a>
</c:if>
<c:if test="${pageIndex-1>0}">
<a href="#" onClick="page('${pageIndex-1}')">${pageIndex-1}</a> 
</c:if>
<span class="current">${pageIndex}</span>
<c:if test="${pageIndex+1<=pagesCount}">
<a href="#" onClick="page('${pageIndex+1}')">${pageIndex+1}</a> 
</c:if>
<c:if test="${pageIndex+2<=pagesCount}">
<a href="#" onClick="page('${pageIndex+2}')">${pageIndex+2}</a>
</c:if>
<c:if test="${pageIndex+3<=pagesCount}">
<a href="#" onClick="page('${pageIndex+3}')">${pageIndex+3}</a>
</c:if>
<c:choose>
<c:when test="${pageIndex==pagesCount}">
<span class="next">下一页</span>
<span class="next">末页</span>
</c:when>
<c:otherwise>
<a href="#" onClick="page('${pageIndex+1}')" class="pagenum">下一页</a>
<a href="#" onClick="page('${pagesCount}')" class="pagenum" >末页</a>
</c:otherwise>
</c:choose>
<span class="pagejump">${pageIndex}/${pagesCount}页&nbsp;共${total}条&nbsp; 跳到第<input type="text" value="${pageIndex}" size="3" name="pageIndex" id="pageNum1">页<button type="button" onClick="onSubmit();">确定</button></span>
</c:if>
<c:if test="${fn:indexOf(url,'?')!=-1}">
<c:choose>
<c:when test="${pageIndex==1}">
<span class="prev">首页</span>
<span class="prev">上一页</span>
</c:when>
<c:otherwise>
<a href="#" onClick="page('1')" class="pagenum" >首页</a>
<a href="#" onClick="page('${pageIndex-1}')" class="pagenum" >上一页</a>
</c:otherwise>
</c:choose>
<c:if test="${pageIndex-3>0}">
<a href="#" onClick="page('${pageIndex-3}')">${pageIndex-3}</a>
</c:if>
<c:if test="${pageIndex-2>0}">
<a href="#" onClick="page('${pageIndex-2}')">${pageIndex-2}</a>
</c:if>
<c:if test="${pageIndex-1>0}">
<a href="#" onClick="page('${pageIndex-1}')">${pageIndex-1}</a> 
</c:if>
<span class="current">${pageIndex}</span>
<c:if test="${pageIndex+1<=pagesCount}">
<a href="#" onClick="page('${pageIndex+1}')">${pageIndex+1}</a> 
</c:if>
<c:if test="${pageIndex+2<=pagesCount}">
<a href="#" onClick="page('${pageIndex+2}')">${pageIndex+2}</a>
</c:if>
<c:if test="${pageIndex+3<=pagesCount}">
<a href="#" onClick="page('${pageIndex+3}')">${pageIndex+3}</a>
</c:if>
<c:choose>
<c:when test="${pageIndex==pagesCount}">
<span class="next">下一页</span>
<span class="next">末页</span>
</c:when>
<c:otherwise>
<a href="#" onClick="page('${pageIndex+1}')" class="pagenum">下一页</a>
<a href="#" onClick="page('${pagesCount}')" class="pagenum" >末页</a>
</c:otherwise>
</c:choose>
<span class="pagejump">${pageIndex}/${pagesCount}页&nbsp;共${total}条&nbsp; 跳到第<input type="text" value="${pageIndex}" size="3" name="pageIndex" id="pageNum1">页<button type="button" onClick="onSubmit();">确定</button></span>
</c:if>
</form>
</div>
</c:if> 
<c:if test="${pagesCount==0}">
<c:choose>  
   <c:when test="${url=='subscriptionList.do'}">
        <h1>对不起,该订阅词相关新闻,暂时还没有被搜索引擎收录;我们最迟在明天收录进来,敬请谅解,谢谢!</h1>
   </c:when>  
   <c:otherwise>
        <h1>对不起,搜索无结果,换个其它搜索词试一下:)</h1>
   </c:otherwise>  
</c:choose> 
</c:if>

分页调用:

<c:import url="common/pages.jsp">
		      <c:param name="total" value="${newList.pagination.rowsCount}"/>
		      <c:param name="pageSize" value="${newList.pagination.pageSize}"/>
		      <c:param name="pageUrl" value="searchList.do"/>
		      <c:param name="pageIndex" value="${newList.pagination.curIndex}"/>
		      <c:param name="pagesCount" value="${newList.pagination.pagesCount}"/>
		      <c:param name="keywords" value="${param.searchText}"/>
		    </c:import>



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值