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 map){

    //根据条件分页查询
    Page
pageDate = articleService.findByPage(map,page,size); //封装分页返回对象 PageResult
pageResult =new PageResult<>( pageDate.getTotal(),pageDate.getRecords() ); return new Result(true,StatusCode.OK,"查询分页成功",pageResult); }

编写service

public Page
findByPage(Map map, Integer page, Integer size) { //设置查询条件 EntityWrapper
wrapper =new EntityWrapper<>(); Set 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
pageData =new Page<>(page,size); //第一个是分页参数,第二个是查询条件 List
list = articleDao.selectPage(pageData, wrapper); pageData.setRecords(list); return pageData; }

整合完成!!!

到此这篇关于springboot整合mybatis-plus 实现分页查询功能的文章就介绍到这了,更多相关mybatis-plus 分页查询内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(springboot整合mybatis-plus 实现分页查询功能)