mybatis分页插件PageHelper简单应用

--添加依赖

<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>

<!--boot框架可引入该依赖 https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>

--springboot配置(.yml)

#pagehelper
pagehelper:
    helperDialect: mysql
    #设置超过最大页数不再返回数据
    reasonable: false
    supportMethodsArguments: true
    params: count=countSql
    returnPageInfo: check

--简单使用(对于线程安全问题可以参考官网,注意对于大数据量,会用性能瓶颈)

int pageNum = Integer.parseInt(request.getParameter("pageNum"));
int pageSize = Integer.parseInt(request.getParameter("pageSize"));
PageHelper.startPage(pageNum,pageSize);
List<Map<String,Object>> list = getMarkersiteListNew(paramMap);
PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
Map<String,Object> listMap = new HashMap<>();
listMap.put("list",list);
listMap.put("pageNum",pageNum);
listMap.put("pageSize",pageSize/*list.size()*/);
listMap.put("total",pageInfo.getTotal());

posted @ 2019-07-12 22:07  qing222  阅读(397)  评论(0编辑  收藏  举报