JSP-翻页功能

jsp页面部分: 

<nav>
    <ul class="pagination">
        <c:forEach items="${functionName}" var="function" varStatus="status">

			<%--此处隐藏用于传值,将当前参数传出--%>
            <li style="display: none">
                <c:if test="${function.condition1 != null}">
                    <input type="text" id="condition1" value="${function.condition1}">
                </c:if>
                <c:if test="${function.condition2 != null}">
                    <input type="text" id="condition2" value="${function.condition2}">
                </c:if>
            </li>

            <%--显示6页中间页[begin=起始页,end=最大页]--%>
            <c:choose>
                <%--总页数没有6页--%>
                <c:when test="${function.pagesNum <= 6}">
                    <c:set var="begin" value="1"/>
                    <c:set var="end" value="${function.pagesNum}"/>
                </c:when>
                <%--页数超过了6页--%>
                <c:otherwise>
                    <c:set var="begin" value="${function.currentPage - 1}"/>
                    <c:set var="end" value="${function.currentPage + 3}"/>
                    <%--如果begin减1后为0,设置起始页为1,最大页为6--%>
                    <c:if test="${begin -1 <= 0}">
                        <c:set var="begin" value="1"/>
                        <c:set var="end" value="6"/>
                    </c:if>
                    <%--如果end超过最大页,设置起始页=最大页-5--%>
                    <c:if test="${end > function.pagesNum}">
                        <c:set var="begin" value="${function.pagesNum - 5}"/>
                        <c:set var="end" value="${function.pagesNum}"/>
                    </c:if>
                </c:otherwise>
            </c:choose>


            <%--如果是第一页,不允许点击--%>
            <c:choose>
                <c:whe
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package com; public class Pager { private int totalRows = 0; // 记录总数 private int totalPages = 0; // 总页数 private int pageSize = 10; // 每页显示数据条数,默认为10条记录 private int currentPage = 1; // 当前页数 private boolean hasPrevious = false; // 是否有上一页 private boolean hasNext = false; // 是否有下一页 public int getSearchFrom() { return (currentPage - 1) * pageSize; } public Pager() { } public void init(int totalRows) { this.totalRows = totalRows; this.totalPages = ((totalRows + pageSize) - 1) / pageSize; refresh(); // 刷新当前页面信息 } /** * * @return Returns the currentPage. * */ public int getCurrentPage() { return currentPage; } /** * * @param currentPage * current page * */ public void setCurrentPage(int currentPage) { this.currentPage = currentPage; refresh(); } /** * * @return Returns the pageSize. * */ public int getPageSize() { return pageSize; } /** * * @param pageSize * The pageSize to set. * */ public void setPageSize(int pageSize) { this.pageSize = pageSize; refresh(); } /** * * @return Returns the totalPages. * */ public int getTotalPages() { return totalPages; } /** * * @param totalPages * The totalPages to set. * */ public void setTotalPages(int totalPages) { this.totalPages = totalPages; refresh(); } /** * * @return Returns the totalRows. * */ public int getTotalRows() { return totalRows; } /** * * @param totalRows * The totalRows to set. * */ public void setTotalRows(int totalRows) { this.totalRows = totalRows; refresh(); } // 跳到第一页 public void first() { currentPage = 1; this.setHasPrevious(false); refresh(); } // 取得上一页(重新设定当前页面即可) public void previous() { if (currentPage > 1) { currentPage--; } refresh(); } // 取得下一页 public void next() { //System.out.println("next: totalPages: "

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值