有問題找:qq 185624592
1.使用到的工具 maven位址
我這邊用的是pagehelper 也可以用其他的
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2.分頁代碼
1.新增redis list資料
List<Entity> entitys=資料庫查詢;
//建立一個用來接收序列化對象的list
List<String> strings = Lists.newLinkedList();
//如果list不為空-> 将list對象序列化後 存到 strings 清單
//JSON 是fastjson
if (CollectionPersonUtils.arrayNotNull(entitys)) {
entitys.stream().forEach(f -> strings.add(JSON.toJSONString(f)));
}
Collection c = strings;
//把strings 通過rightPush加到redis
redisUtils.rightPushAll("Entity_CASH", c);
2.查詢redis list清單 并分頁
//這個是PageHelper 開啟分頁插件
Page page = PageHelper.startPage(dto.getCurrentPage(), dto.getPageSize());
//這個是分頁擷取redis list資訊 page.getStartRow()=開始行 page.getEndRow()=結束行
List<Object> objs=redisUtils.listRange("Entity_CASH",page.getStartRow(),page.getEndRow());
//擷取總共有多少條資料
Long listSize=redisUtils.getListSize("Entity_CASH");
if(listSize!=null){
page.setTotal(listSize);
}
List<EntityVO> entitys=Lists.newLinkedList();
if(objs!=null){
entitys=JSON.parseArray(objs.toString(), EntityVO.class);
}
分頁的資訊-page;
list結果集-forecastVOS;
return;