jstl 实现分页效果

代码部分

        <div class="pagination center">
            <b>共${page.pageCount}页</b>
            <c:choose>
                <c:when test="${page.currentPage+1 == 1}">
                    <a class="navlinks current">首页 </a>
                    <a class="pagebtn" style="font-size: 12px;color: #454545;background-color: #eee;font-weight: 600;text-transform: uppercase;padding: 7px 10px;border-radius: 3px;margin-left: 5px;margin-right:5px;"><上一页 </a>
                </c:when>
                <c:otherwise>
                    <a href='${pageContent.request.contextPath}/news?currentPage=0&type=${page.type}' class="navlinks">首页 </a>
                    <a href='${pageContent.request.contextPath}/news?currentPage=${page.currentPage-1}&type=${page.type}' class="navlinks pagebtn"style="margin-left: 5px;margin-right:5px"><上一页 </a>
                </c:otherwise>
            </c:choose>
            <c:choose>
                <c:when test="${page.pageCount+1 <= 5}">
                    <c:forEach begin="1" end="${page.pageCount}" varStatus="s">
                        <c:choose>
                            <c:when test="${s.index == page.currentPage+1}">
                                <a href="${pageContent.request.contextPath}/news?currentPage=${s.index-1}&type=${page.type}" class="navlinks current">${s.index}</a>
                            </c:when>
                            <c:otherwise>
                                <a href="${pageContent.request.contextPath}/news?currentPage=${s.index-1}&type=${page.type}" class="navlinks">${s.index}</a>
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>
                </c:when>
                <c:otherwise>
                    <c:choose>
                        <c:when test="${page.currentPage+1-1 > 2}">
                            <c:choose>
                                <c:when test="${page.currentPage+3 >= page.pageCount}">
                                    <c:forEach begin="${page.pageCount-4}" end="${page.pageCount}" varStatus="s">
                                        <c:choose>
                                            <c:when test="${s.index == page.currentPage+1}">
                                                <a href="${pageContent.request.contextPath}/news?currentPage=${s.index-1}&type=${page.type}" class="navlinks current">${s.index}</a>
                                            </c:when>
                                            <c:otherwise>
                                                <a href="${pageContent.request.contextPath}/news?currentPage=${s.index-1}&type=${page.type}" class="navlinks">${s.index}</a>
                                            </c:otherwise>
                                        </c:choose>
                                    </c:forEach>
                                </c:when>
                                <c:otherwise>
                                    <a href="${pageContent.request.contextPath}/news?currentPage=${page.currentPage-2}&type=${page.type}" class="navlinks">${page.currentPage+1-2}</a>
                                    <a href="${pageContent.request.contextPath}/news?currentPage=${page.currentPage-1}&type=${page.type}" class="navlinks">${page.currentPage+1-1}</a>
                                    <a href="${pageContent.request.contextPath}/news?currentPage=${page.currentPage}&type=${page.type}" class="navlinks current">${page.currentPage+1}</a>
                                    <a href="${pageContent.request.contextPath}/news?currentPage=${page.currentPage+1}&type=${page.type}" class="navlinks">${page.currentPage+1+1}</a>
                                    <a href="${pageContent.request.contextPath}/news?currentPage=${page.currentPage+1+1}&type=${page.type}" class="navlinks">${page.currentPage+1+2}</a>
                                </c:otherwise>
                            </c:choose>
                        </c:when>
                        <c:otherwise>
                            <c:forEach end="5" begin="1" varStatus="s">
                                <c:choose>
                                    <c:when test="${s.index == page.currentPage+1}">
                                        <a href="${pageContent.request.contextPath}/news?currentPage=${s.index-1}&type=${page.type}" class="navlinks current">${s.index}</a>
                                    </c:when>
                                    <c:otherwise>
                                        <a href="${pageContent.request.contextPath}/news?currentPage=${s.index-1}&type=${page.type}" class="navlinks">${s.index}</a>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </c:otherwise>
                    </c:choose>
                </c:otherwise>
            </c:choose>
            <c:choose>
                <c:when test="${page.currentPage+1 == page.pageCount}">
                    <a class="pagebtn"style="font-size: 12px;color: #454545;background-color: #eee;font-weight: 600;text-transform: uppercase;padding: 7px 10px;border-radius: 3px;"> 下一页></a>
                    <a class="navlinks current"> 末页</a>
                </c:when>
                <c:otherwise>
                    <a href="${pageContent.request.contextPath}/news?currentPage=${page.currentPage+1}&type=${page.type}" class="navlinks pagebtn"> 下一页></a>
                    <a href="${pageContent.request.contextPath}/news?currentPage=${page.pageCount-1}&type=${page.type}" class="navlinks"> 末页</a>
                </c:otherwise>
            </c:choose>
        </div>

效果实现


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值