List<Map> collect = maps.stream()
.skip((page - 1) * limit)
.limit(limit)
.collect(Collectors.toList());
float count = maps.stream().count();
//计算最大页数
float number = count / limit;
int renewNum = (int)Math.ceil(number);
Map<String, Object> hashMap = new HashMap<>();
hashMap.put("total", count);
hashMap.put("size", limit);
hashMap.put("pages", renewNum);
hashMap.put("list",collect);
利用java8,stream流做分页,适合数据量少的时候使用
最新推荐文章于 2024-06-06 15:47:46 发布