pageInfo paging conditional query + query condition echo in java

The code is as follows: parse below
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/1/17
  Time: 19:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="/jquery-1.10.2.min.js"></script>
    <style>
        body{ text-align:center}
        #div{
            background: gray;
            border:1px solid #000;
            width:600px;
            height:300px;
            position:relative;
            top: 50px;
            left: 100px;
        }
    </style>
</head>
<body>
<div id="div">
    <form id="form" action="/sale/list.html">
        <input type="hidden" name="pageNum" id="pageNum"/>
   Sales information query: Sort by <select name="order" ">
            <option value="created_date" ${param.order=='created_date'?"selected":""}>日期</option>
            <option value="total" ${param.order=='total'?"selected":""}>单笔总额</option>
       </select>
        <input type="submit" value="提交 "/>
    </form>
    <table border="1">

        <tr>
            <td>id</td>
            <td>商品</td>
            <td>Unit Price</td>
            <td>数量</td>
            <td>Total Price</td>
            <td>Sale Date</td>
            <td>Salesperson</td>
        </tr>
        <c:forEach items="${pageInfo.list}" var="sale">
            <tr>
                <td>${sale.id}</td>
                <td>${sale.product.proName}</td>
                <td>${sale.saleSize}</td>
                <td>${sale.saleNum}</td>
                <td>${sale.total}</td>
                <%--<fmt:formatDate value="${sale.createDate}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>--%>
                <td><fmt:formatDate value="${sale.createdDate}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate></td>
                <td>${sale.userName}</td>
            </tr>
        </c:forEach>
        <tr><td colspan="7">         
            <a href="#" onclick="page(1)">首页</a>|
            <a  href="#" onclick="page(${pageInfo.pageNum-1})">上一页</a>|
            <a  href="#" onclick="page(${pageInfo.pageNum+1})">下一页</a>|
            <a href="#" onclick="page(${pageInfo.pages})">末页</a>|
            Page ${pageInfo.pageNum}/
            Total ${pageInfo.pages} pages
            (${pageInfo.total} data)</td></tr>
    </table>
<script>
function page(pageNum) {
    $("#pageNum").val(pageNum);
    $("#form").submit();
}
</script>
</div>
</body>
</html>
Analysis: Put the query conditions into the form, and add a hidden tag to the form
  <input type="hidden" name="pageNum" id="pageNum"/>
Add method below pagination
onclick="page(1); the parameter in page is pegeNum  
add method in javascript
function page(pageNum) {
    $("#pageNum").val(pageNum);
    $("#form").submit();
} And set the value to the hidden tag; call the submit function through the id in the form to submit the form

Note: For data echo, param. attribute name is used for ordinary data

Special data requires special methods

The code and analysis are as follows

controller
public String list(Employee employee,Model model,@RequestParam(defaultValue = "price")String order,@RequestParam(defaultValue = "1") Integer pageNum){
    List<Dept> deptList = deptService.getDeptList();
    List<Position> positionList = positionService.getPositionList();
    PageInfo<Employee> pageInfo = employeeService.getEmpList(employee,pageNum,3,order);
    model.addAttribute ("deptList", deptList);
    model.addAttribute("positionList",positionList);
    model.addAttribute("pageInfo",pageInfo);
    return "emp_list";
}
<c:forEach items="${deptList}" var="dept">
    <option value="${dept.id}" ${employee.dept.id==dept.id?'selected':''}>${dept.name}</option>
</c:forEach>

Here dept is a persistent class; as a property of the persistent class Employee;
If you want to echo, you need to use the lowercase employee.dept.id of the persistent class Employee passed into the controller to echo your data
${employee.dept.id==dept.id?'selected':''} 3-eye judgment and echo data
 
 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325874994&siteId=291194637