mybatis分页插件PageHelper简单应用

it2022-05-05  95

--添加依赖

<!-- 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)

#pagehelperpagehelper:     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());

转载于:https://www.cnblogs.com/sung1024/p/11178691.html


最新回复(0)