ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 控制器定义 在Controller中返回分页对象Page变量名为`page`,下面代码为字典列表实例! ```java public String index(Model model, Dict dict){ // 创建匹配器,进行动态查询匹配 ExampleMatcher matcher = ExampleMatcher.matching(). withMatcher("title", match -> match.contains()); // 获取字典列表 Example<Dict> example = Example.of(dict, matcher); Page<Dict> list = dictService.getPageList(example); // 封装数据 model.addAttribute("list", list.getContent()); model.addAttribute("page", list); return "/system/dict/index"; } ``` ## service定义 在业务层中可通过PageSort创建一个分页请求对象,也可自行创建分页请求对象,下面代码为字典业务层实例! ``` public Page<Dict> getPageList(Example<Dict> example) { // 创建分页对象 PageRequest page = PageSort.pageRequest(); return dictRepository.findAll(example, page); } ``` ## 视图模板定义 ```html <div th:replace="/common/fragment :: page"></div> ```