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" >没有数据可以显示</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;

相关文章:

  • 2021-09-29
  • 2022-02-06
  • 2021-04-09
  • 2021-10-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2017-12-07
  • 2018-07-26
  • 2019-03-26
相关资源
相似解决方案