[SaaS-Export Project] 07-jsp page reuse, pagehelper realizes paging, paging jsp reuse

jsp code reuse

1) <jsp:include>Reuse by including pages,
such as reusing B.jsp pages in current page A

<!-- 页面重用 -->
<jsp:include page="B.jsp" />

2) The current page A passes through <jsp:param>to pass parameters to the B.jsp page, and B passes ${param.xxx}to obtain

<!-- 页面A传递参数 -->
<jsp:include page="B.jsp">
	<jsp:param name="username" value="strive_day"/>
</<jsp:include>

<!-- 页面B获取参数username的值 -->
${param.username}

Case:
jspinclude_A.jsp

    <%-- 子标签param,将k-v键值对的值传给被include重用的页面 --%>
    <h3>jsp:include调用B并且传递参数</h3>
        <%-- 传递键值对,分页可以通过传地址实现 --%>
    <jsp:include page="/testjsp/jspinclude_B.jsp">
        <jsp:param name="username" value="strive_day" ></jsp:param>
        <jsp:param name="url" value="http://www.baiud.com" ></jsp:param>
    </jsp:include>
    
    <h3>jsp:include调用B并不进行参数传递</h3>
    <jsp:include page="/testjsp/jspinclude_B.jsp"></jsp:include>

jspinclude_B.jsp

	<h3>我是可以重用的jsp代码部分(jspinclude_B)</h3>
    username : ${param.username}
    <br/>
    url : ${param.url}<%--分页需要使用地址参数,可以通过该方法实现--%>

operation result:
Insert picture description here



Page display company information

Insert picture description here

1. Paging code reuse

common/page.jspPagination information can be reused in the future.

<%-- 分页 公共部分 --%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<body>
<div class="pull-left">
    <div class="form-group form-inline">
        <%-- pi --%>
        总共${pi.pages} 页,共${pi.total} 条数据。
    </div>
</div>

<div class="box-tools pull-right">
    <ul class="pagination" style="margin: 0px;">
        <li >
            <%-- goPage(1)去第一页 --%>
            <a href="javascript:goPage(1)" aria-label="Previous">首页</a>
        </li>
        <%-- c:if判断,如果是第一页,就不显示上一页按钮 --%>
        <c:if test="${pi.pageNum != 1 }">
            <li><a href="javascript:goPage(${pi.prePage})">上一页</a></li>
        </c:if>

        <c:forEach begin="1" end="${pi.pages}" var="i">
            <%-- 循环显示页数,如果页数是当前页,就active的css效果,高亮,点击页数就跳转goPage(i)指定页面 --%>
            <li class="paginate_button ${pi.pageNum==i ? 'active':''}"><a href="javascript:goPage(${i})">${i}</a></li>
        </c:forEach>
        
        <c:if test="${pi.pageNum != pi.pages }">
            <li><a href="javascript:goPage(${pi.nextPage})">下一页</a></li>
        </c:if>

        <li>
            <a href="javascript:goPage(${pi.pages})" aria-label="Next">尾页</a>
        </li>
    </ul>
</div>
<form id="pageForm" action="${param.pageUrl}" method="post">
    <input type="hidden" name="curr" id="curr">
    <input type="hidden" name="pageSize" id="pageSize">
</form>
<script>
    //goPage重新发送请求,请求page页
    function goPage(page) {
     
     
        //跳转到page页显示为当前页
        document.getElementById("curr").value = page
        //每页多少数据
        document.getElementById("pageSize").value = ${
     
     pi.pageSize}
            document.getElementById("pageForm").submit()
    }
</script>
</body>
</html>

2. By introducing pagination in the page

<div class="box-footer">
	<%-- 分页页面重用,将url参数传给分页页面,分页页面通过表单提交${param.pageUrl}获取地址来实现分页 --%>
	<jsp:include page="../common/page.jsp">
		<jsp:param value="${path}/company/toList" name="pageUrl"/>
	</jsp:include>
</div>

Guess you like

Origin blog.csdn.net/qq_40542534/article/details/109383415