zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    路径专题
    java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.Integer
    DER input, Integer tag error的异常处理
    myeclipse,eclipse控制台输出乱码问题
    大话设计模式之简单工厂模式
    Maven安装与配置
    IDEA: 遇到问题Error during artifact deployment. See server log for details.详解
    IntelliJ IDEA 中 右键新建时,选项没有Java class的解决方法和具体解释
    微信内置浏览器和小程序的 User Agent 区别及判断方法
    WAMP 403 Forbidden禁止访问
  • 原文地址:https://www.cnblogs.com/Xuesk/p/7461447.html
Copyright © 2011-2022 走看看