springboot整合mybatis-plus 实现分页查询功能
更新时间:2020年09月08日 14:11:47 作者:小小雨伞
这篇文章主要介绍了springboot整合mybatis-plus 实现分页查询功能,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
建一个config类
@Configuration
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor(){
return new PaginationInterceptor();
}
}
编写controller
post /article/search/{page}/{size}
@PostMapping("search/{page}/{size}")
public Result findByPage(@PathVariable Integer page,
@PathVariable Integer size,
@RequestBody Map<String,Object> map){
//根据条件分页查询
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
public Page<Article> findByPage(Map<String, Object> map, Integer page, Integer size) {
//设置查询条件
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));
}
//设置分页参数
Page<Article> pageData =new Page<>(page,size);
//第一个是分页参数,第二个是查询条件
List<Article> list = articleDao.selectPage(pageData, wrapper);
pageData.setRecords(list);
return pageData;
}
整合完成!!!
到此这篇关于springboot整合mybatis-plus 实现分页查询功能的文章就介绍到这了,更多相关mybatis-plus 分页查询内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
聊聊ResourceBundle和properties读取配置文件的区别
这篇文章主要介绍了ResourceBundle和properties读取配置文件的区别,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2021-07-07


最新评论