该工具类用于分页Page对象转为Map,然后存储到Redis中
import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import java.util.HashMap; import java.util.Map; public class PageToCacheMapUtils<T> { public static <T> Page<T> cacheMapToPage(Map<String, String> cacheVal, Class<T> clazz) { Page<T> page = new Page<>(); page.setCurrent(Long.valueOf(cacheVal.get("current"))); page.setSize(Long.valueOf(cacheVal.get("size"))); page.setTotal(Long.valueOf(cacheVal.get("total"))); page.setRecords(JSON.parseArray(cacheVal.get("records"), clazz)); return page; } public static <T> Map<String, String> pageToCacheMap(Page<T> pageData) { Map<String, String> cacheVal = new HashMap<>(); cacheVal.put("current", String.valueOf(pageData.getCurrent())); cacheVal.put("size", String.valueOf(pageData.getSize())); cacheVal.put("total", String.valueOf(pageData.getTotal())); cacheVal.put("records", JSON.toJSONString(pageData.getRecords())); return cacheVal; } }