分页的使用

1.添加页面的规范使用

<%--
  Created by IntelliJ IDEA.
  User: zhangxiaohu
  Date: 2017/8/11
  Time: 10:39
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--加上这段java代码 --%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<html>
<head>
    <title>欢迎</title>
    <script src="/resources/jquery/jquery-1.8.3.js"></script>
    <script type="text/javascript">

        $(function () {

            $("#houseName").blur(function() {
                $("#s2").empty();
                houseName=$(this).val();
                if(houseName==null||houseName==""){
                    $("#s2").html("房产名称不可为空!");
                }else {
                    $.ajax({
                        type:"post",
                        url:"${pageContext.request.contextPath }/house/selHouseByName.action",
                        data:{
                            houseName:houseName
                        },
                        dataType:"json",
                        success:function (data) {
                            if(data.flag==1){
                                alert("用户名可用!");
                            }else {
                                alert("用户名不可用,用户名不能重!");
                            }
                        },
                        error:function () {
                            alert("系统繁忙,请稍候再试!");
                        }
                    });

                }
            });
        });

    </script>
</head>
<body>
<p2>添加页面</p2><br/>
<form action="/house/addHouse.action" enctype="multipart/form-data" method="post">
房产名称: <input type="text" name="houseName" id="houseName" /><span id="s2"></span><br/>
房产图片 :<input type="file" name="file"/><br/>
房产单价 : <input type="text" name="housePrice" id="housePrice" /><br/>
房产面积 : <input type="text" name="houseArea" id="houseArea" /><br/>
所属户主 : <select name="personId">
    <option value="">请选择</option>
    <c:forEach items="${sessionScope.holderNameList}" var="customer">
        <option value="${customer.id}">${customer.holderName}</option>
    </c:forEach>
</select><br/>
    <input type="submit" value="注册"/>
</form>

</body>
</html>


2.项目的展示分页

<%--
  Created by IntelliJ IDEA.
  User: zhangxiaohu
  Date: 2017/8/11
  Time: 10:39
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<%--加上这段java代码 --%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<html>
<head>
    <title>欢迎</title>
    <script src="/resources/jquery/jquery-1.8.3.js"></script>
    <script>
        function checkAll() {
            $("input[id='features2']").each(
                function () {
                    if($(this).prop("checked")){
                        $(this).removeAttr("checked");
                    }else {
                        $(this).prop("checked","true");
                    }
                });
        }

        function batchHouse() {
            var checkedNum = $("input[name='features']:checked").length;
            if(checkedNum == 0) {
                alert("请选择至少一项!");
                return;
            }
            if(confirm("确定要删除所选项目?")) {
                var checkedList=[];
                $("input[name='features']:checked").each(function () {
                    checkedList.push($(this).val());
                });
                ids=checkedList.toString();
                $.ajax({
                    type:"post",
                    url:"/house/delBatchHouse.action",
                    data:{
                        ids:ids
                    },
                    dataType:"json",
                    success:function (data) {
                        alert(data.flag);
                        location.href="/house/findAllHouse.action";
                    },
                    error:function () {
                        alert("出现错误,稍后再试!");
                    }
                });
            }
        }

    function person() {
    var personId=$("#personId").val();
        $.ajax({
            type:"post",
            url:"/house/findPerson.action",
            data:{
                holderName:personId
            },
            dataType:"json",
            success:function (data) {
                    alert(data.flag2);
                    location.href="/house/fuzzyHouseAll.action";
            },
            error:function () {
                alert("出现错误,稍后再试!");
            }
        });
    }
    </script>
</head>
<body>
<p2>展示页面</p2><br/>

<form action="/house/findHouseAll.action" method="post">
    模糊查询房产名:<input type="text" name="houseName"/>
    <input type="submit" value="搜索"/>
</form>    
<a href="/house/selHolder.action">添加房屋信息</a>
<input type="button" value="全选/全不选" id="hide" οnclick="checkAll()"/>
<input type="button" value="批量删除" οnclick="batchHouse()"/>    
根据户主名查询:<select name="personId" id="personId" οnchange="person()">
    <option value="">请选择</option>
    <c:forEach items="${sessionScope.holderNameList}" var="customer">
        <option value="${customer.holderName}">${customer.holderName}</option>
    </c:forEach>
</select><br/>
<table border="1">
    <tr>
        <td>复选框</td>
        <td>房产id</td>
        <td>房产名称</td>
        <td>房产图片</td>
        <td>房产面积</td>
        <td>房产单价</td>
        <td>房产总价</td>
        <td>所属户主</td>
        <td>购买日期</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${houseList}" var="house">
        <tr>
            <td> <input type="checkbox" id="features2" name="features" value="${house.id}"/></td>
            <td> ${house.id}</td>
            <td>${house.houseName}</td>
            <td><img src="${house.houseImg}"/></td>
            <td>${house.houseArea}</td>
            <td>${house.housePrice}</td>
            <td>${house.houseTotal}</td>
            <td>${house.holderName}</td>
            <td><f:formatDate value="${house.buyDate }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
            <td>
                <a href="/house/selHouseById.action?id=${house.id}">修改</a>
                <a href="/house/delHouse.action?id=${house.id}">删除</a>
            </td>
        </tr>
    </c:forEach>
</table>    <br/>
<form action="/house/findHouseAll.action" method="post">
    输入起始页:<input type="text" name="begin"/>
     输入每页的条数: <input type="text" name="pageSize"/><br/>
    <input type="submit" value="查询"/>
</form>
</body>
</html>


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PageHelper 是一个基于 MyBatis 的分页插件,它可以通过拦截 Executor 的方式,在 SQL 执行前自动进行分页操作,简化了分页操作的繁琐步骤。 使用 PageHelper 进行分页操作,需要以下步骤: 1. 引入 PageHelper 依赖 Maven 依赖: ```xml <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.11</version> </dependency> ``` 2. 配置 PageHelper 插件 在 MyBatis 配置文件中添加如下配置: ```xml <plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"> <property name="helperDialect" value="mysql"/> <property name="reasonable" value="true"/> <property name="supportMethodsArguments" value="true"/> </plugin> </plugins> ``` 其中,`helperDialect` 表示数据库类型(支持的数据库类型详见官方文档),`reasonable` 表示是否启用合理化查询(即当查询页码小于 1 或大于总页数时,自动查询第一页或最后一页),`supportMethodsArguments` 表示是否支持分页参数的绑定(即在方法参数中直接传入分页参数)。 3. 在需要分页的查询方法中使用 PageHelper.startPage 方法 在需要进行分页的查询方法中,使用 `PageHelper.startPage` 方法设置分页参数,例如: ```java public PageInfo<User> queryUserList(int pageNum, int pageSize) { PageHelper.startPage(pageNum, pageSize); List<User> userList = userMapper.queryUserList(); return new PageInfo<>(userList); } ``` 其中,`startPage` 方法的两个参数分别表示当前页码和每页显示条数。 4. 获取分页结果 使用 `PageInfo` 对象包装查询结果,即可获取分页相关的信息: ```java PageInfo<User> pageInfo = userService.queryUserList(1, 10); List<User> userList = pageInfo.getList(); // 当前页的数据列表 int pageNum = pageInfo.getPageNum(); // 当前页码 int pageSize = pageInfo.getPageSize(); // 每页显示条数 int total = pageInfo.getTotal(); // 总记录数 int pages = pageInfo.getPages(); // 总页数 ``` 以上就是使用 PageHelper 进行分页操作的基本步骤。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值