1.导入坐标
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>3.7.5</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>0.9.1</version>
</dependency>
2.sqlMapconfig.xml中配置插件类
<!-- 注意:分页助手的插件 配置在通用mapper之前 -->
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 指定方言 -->
<property name="dialect" value="mysql"/>
</plugin>
3.使用分页
//设置分页参数
PageHelper.startPage(1,2);
List<User> select = userMapper2.select(null);
for(User user : select){
System.out.println(user);
}
//其他分页数据
PageInfo<User> pageInfo = new PageInfo<User>(select);
System.out.println("总条数"+pageInfo.getTotal());
System.out.println("总页数 "+pageInfo.getPages());
System.out.println("当前页 "+pageInfo.getPageNum());
System.out.println("ྯ每页展示条数"+pageInfo.getPageSize());
System.out.println("是否第一页"+pageInfo.isIsFirstPage());
System.out.println("是否最后一页"+pageInfo.isIsLastPage());
网友评论