java中pageInfo分页带条件查询+查询条件的回显

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Abraham_bug/article/details/79100619
代码如下:解析在下边
<%@ 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"/>
   销售信息查询:      排序方式<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>单价</td>
            <td>数量</td>
            <td>总价</td>
            <td>销售日期</td>
            <td>销售人员</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>|
            第${pageInfo.pageNum}页/
            共${pageInfo.pages}页
            (${pageInfo.total}条数据)</td></tr>
    </table>
<script>
function page(pageNum) {
    $("#pageNum").val(pageNum);
    $("#form").submit();
}
</script>
</div>
</body>
</html>
解析:将查询条件放入到到form表单中,在form中添加一个隐藏标签
  <input type="hidden" name="pageNum" id="pageNum"/>
在分页下边添加方法
onclick="page(1);page内的参数是pegeNum  
在JavaScript中添加方法
function page(pageNum) {
    $("#pageNum").val(pageNum);
    $("#form").submit();
} 并且给 隐藏标签设值;通过form中的id调用submit函数提交form表单

注意:数据的回显  普通数据用param.属性名

特殊数据则需要特殊的方法

代码及解析如下

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>

在这里 dept是持久化类 ;作为持久化类Employee的属性;
如果你要回显需要用传入controller的持久化类Employee的首字母小写employee.dept.id  来回显你的数据
${employee.dept.id==dept.id?'selected':''}三目判断回显数据




展开阅读全文

没有更多推荐了,返回首页