建一個config類
1
2
3
4
5
6
7
8
|
@Configuration public class MybatisPlusConfig { @Bean public PaginationInterceptor paginationInterceptor(){ return new PaginationInterceptor(); } } |
編寫controller
1
|
post /article/search/{page}/{size} |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
@PostMapping ( "search/{page}/{size}" ) public Result findByPage( @PathVariable Integer page, @PathVariable Integer size, @RequestBody Map<String,Object> map){ //根據(jù)條件分頁查詢 Page<Article> pageDate = articleService.findByPage(map,page,size); //封裝分頁返回對象 PageResult<Article> pageResult = new PageResult<>( pageDate.getTotal(),pageDate.getRecords() ); return new Result( true ,StatusCode.OK, "查詢分頁成功" ,pageResult); } |
編寫service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public Page<Article> findByPage(Map<String, Object> map, Integer page, Integer size) { //設(shè)置查詢條件 EntityWrapper<Article> wrapper = new EntityWrapper<>(); Set<String> keySet = map.keySet(); for (String key : keySet) { // if (map.get(key) !=null){ // wrapper.eq(key,map.get(key)); // } wrapper.eq(map.get(key) != null ,key,map.get(key)); } //設(shè)置分頁參數(shù) Page<Article> pageData = new Page<>(page,size); //第一個是分頁參數(shù),第二個是查詢條件 List<Article> list = articleDao.selectPage(pageData, wrapper); pageData.setRecords(list); return pageData; } |
整合完成!!!
到此這篇關(guān)于springboot整合mybatis-plus 實(shí)現(xiàn)分頁查詢功能的文章就介紹到這了,更多相關(guān)mybatis-plus 分頁查詢內(nèi)容請搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/qq_42794826/article/details/108466196