Pagehelper 分页插件使用

1.使用maven导入jar包

<dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>5.1.2</version>
    </dependency>

 2.在mybatis-config.xml中添加如下配置:

 <!-- 配置分页插件 -->
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
        
        </plugin>
    </plugins> 

 分页插件版本不同,interceptor 可能会有区别,配置方式根据实际情况配置参数

3.Service层 使用分页插件

Page page = PageHelper.startPage(pageNum,sizeNum,true);
List<MainSearchVo> mainSearchVoList = companyMainPageMapper.getMainSearch(fname);

参数详解:

pageNum:当前页

sizeNum:每页显示条数

count :是否查询总条数 (true:查询 ,false:不查询)

获取总页数:  page.getPages()

猜你喜欢

转载自www.cnblogs.com/lin-mumu/p/10921983.html