pagehelper分页插件的使用

1.pom.xml加入依赖

        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.2.3
        

2.在application.yml里加入以下配置

pagehelper:
  helper-dialect: mysql
  support-methods-arguments: true

3.dao层的方法

List getList(@Param("pageNum") Integer pageNum,
                           @Param("pageSize") Integer pageSize,
                           @Param("status") Integer status);

4.service层的方法

public PageInfo getList(Integer pageNum, Integer pageSize, Integer status) {
        List list = cityShopMapper.getList(pageNum, pageSize, status);
        return new PageInfo<>(list);
    }

5.自定义pageinfo可以过滤一些不想要的字段

package com.szp.springbootlearn.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.List;

public class PageInfo extends com.github.pagehelper.PageInfo {
    public PageInfo(List list){
        super(list);
    }

    @JsonIgnore
    @Override
    public int getPageNum() {
        return super.getPageNum();
    }

    @JsonIgnore
    @Override
    public int getPageSize() {
        return super.getPageSize();
    }

    @JsonIgnore
    @Override
    public int getSize() {
        return super.getSize();
    }

    @JsonIgnore
    @Override
    public int getStartRow() {
        return super.getStartRow();
    }

    @JsonIgnore
    @Override
    public int getEndRow() {
        return super.getEndRow();
    }

    @JsonIgnore
    @Override
    public int getPrePage() {
        return super.getPrePage();
    }

    @JsonIgnore
    @Override
    public int getNextPage() {
        return super.getNextPage();
    }

    @JsonIgnore
    @Override
    public boolean isIsFirstPage() {
        return super.isIsFirstPage();
    }

    @JsonIgnore
    @Override
    public boolean isIsLastPage() {
        return super.isIsLastPage();
    }

    @JsonIgnore
    @Override
    public boolean isHasNextPage() {
        return super.isHasNextPage();
    }

    @JsonIgnore
    @Override
    public boolean isHasPreviousPage() {
        return super.isHasPreviousPage();
    }

    @JsonIgnore
    @Override
    public int getNavigatePages() {
        return super.getNavigatePages();
    }

    @JsonIgnore
    @Override
    public int[] getNavigatepageNums() {
        return super.getNavigatepageNums();
    }

    @JsonIgnore
    @Override
    public int getNavigateFirstPage() {
        return super.getNavigateFirstPage();
    }

    @JsonIgnore
    @Override
    public int getNavigateLastPage() {
        return super.getNavigateLastPage();
    }

    @JsonIgnore
    @Override
    public int getFirstPage() {
        return super.getFirstPage();
    }

    @JsonIgnore
    @Override
    public int getLastPage() {
        return super.getLastPage();
    }
}

你可能感兴趣的:(pagehelper分页插件的使用)