• pageHelper分页插件使用总结


    1、添加jar包货添加pom文件

    <dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>4.0.0</version>
    </dependency>
    2、添加插件配置
    在mybatis-config配置文件中添加插件
    <configuration>
    <!-- 配置分页插件 -->
    <plugins>
    <plugin interceptor="com.github.pagehelper.PageHelper">
    <!-- 指定数据库方言 -->
    <property name="dialect" value="mysql"/>
    </plugin>
    </plugins>
    </configuration>

    3、在controller中方法参数
    @RequestParam(value = "PageNum", defaultValue = "1") Integer PageNum, @RequestParam(value = "PageSize", defaultValue = "5") Integer PageSize


    4、controller内容(最好写在service)
    //设置分页
    PageHelper.startPage(1, 30);
    //执行查询
    list=service.方法;

    //取得分页结果
    PageInfo pageInfo=new PageInfo(list);

    5、页面添加

    <c:choose>
    <c:when test="${pageInfo.size > 0 }">
    <div class="feny">
    <div class="manu">
    <span>显示${pageInfo.startRow }到${pageInfo.endRow}共${pageInfo.total}条</span> <input
    type="hidden" id="page" name="page"> <input type="hidden"
    id="pageSize" name="pageSize"> <a
    href="<%=basePath%>/friend/selectUserAll.action?PageNum=1">首页 </a>
    <c:choose>
    <c:when test="${pageInfo.hasPreviousPage }">
    <a href="<%=basePath%>/friend/selectUserAll.action?PageNum=${pageInfo.pageNum-1}">上一页
    </a>
    </c:when>
    <c:otherwise>
    <span>上一页</span>
    </c:otherwise>
    </c:choose>
    <c:forEach var="item" items="${pageInfo.navigatepageNums}">
    <c:choose>
    <c:when test="${pageInfo.pageNum == item }">
    <span class="current">${pageInfo.pageNum }</span>
    </c:when>
    <c:otherwise>
    <a href="<%=basePath%>/friend/selectUserAll.action?PageNum=${item}">${item}</a>
    </c:otherwise>
    </c:choose>
    </c:forEach>
    <c:choose>
    <c:when test="${!pageInfo.isLastPage }">
    <a href="<%=basePath%>/friend/selectUserAll.action?PageNum=${pageInfo.pageNum+1}">下一页
    </a>
    <a href="<%=basePath%>/friend/selectUserAll.action?PageNum=${pageInfo.lastPage}">尾页</a>
    </c:when>
    <c:otherwise>
    <span>下一页</span>
    <span>尾页</span>
    </c:otherwise>
    </c:choose>
    </div>
    </div>
    </c:when>
    <c:otherwise>
    <div class="feny">
    <span class="emptyData">没有数据可以显示</span>
    </div>
    </c:otherwise>
    </c:choose>

    6、pageInfo 类属性详解
    private int pageNum;//当前页数
    private int pageSize;//当前页面条数
    private int size;//
    private int startRow;
    private int endRow;
    private long total;
    private int pages;
    private List<T> list;
    private int firstPage;//首页
    private int prePage;//上一页
    private int nextPage;//下一页
    private int lastPage;尾页
    private boolean isFirstPage;//是否是第一页
    private boolean isLastPage;//是否是最后一页
    private boolean hasPreviousPage;
    private boolean hasNextPage;
    private int navigatePages;
    private int[] navigatepageNums;

  • 相关阅读:
    游戏架构草稿(1)
    蔡学镛:架构师最重视的文档
    常见拉丁字母
    图像识别学习1
    .net framework 2.0,3.0与3.5之间的关系 [转载]
    ASP.NET Session丢失问题原因及解决方案[转载]
    PLSQL 循环游标 cursor loop fetch into【转载】
    oracle case when的用法 【转载】
    Oracle to_char格式化函数 [转载]
    oracle表关联应用 【转载】
  • 原文地址:https://www.cnblogs.com/Xuesk/p/7461447.html
Copyright © 2020-2023  润新知