spring boot分页插件的使用

多参考网上大神代码

插件坐标

com.github.pagehelper

    pagehelper-spring-boot-starter

    1.0.0

启动类加入

@Bean

public PageHelperpageHelper() {

PageHelper pageHelper =new PageHelper();

    Properties properties =new Properties();

    properties.setProperty("offsetAsPageNum", "true");

    properties.setProperty("rowBoundsWithCount", "true");

    properties.setProperty("reasonable", "true");

    //配置mysql数据库的方言

    properties.setProperty("dialect", "mysql");

    pageHelper.setProperties(properties);

    return pageHelper;

}

我的实体Paging

public class Paging {

private IntegerpageNum;

    private IntegerpageSize;

    public IntegergetPageNum() {

return pageNum;

    }

public void setPageNum(Integer pageNum) {

this.pageNum = pageNum;

    }

public IntegergetPageSize() {

return pageSize;

    }

public void setPageSize(Integer pageSize) {

this.pageSize = pageSize;

    }

}

PageTool

public static void num(Paging paging) {

if (paging.getPageNum() ==null) {

paging.setPageNum(0);

    }

if (paging.getPageSize() ==null) {

paging.setPageSize(0);

    }

PageHelper.startPage(paging.getPageNum(), paging.getPageSize());

}

controller调用

@RequestMapping(value ="/login123", method = RequestMethod.GET)

@ApiOperation(value ="分页查询查询123", notes ="分页查询查询123")

public ResponseEntitylogin123(Paging paging)throws Exception {

ResponseEntity.BodyBuilder builder = ResponseUtils.getBodyBuilder();

    PageTool.num(paging);

    PageInfo pageInfo =new PageInfo<>(hfUserMapper.selectAll());

    return builder.body(ResponseUtils.getResponseBody(pageInfo));

}


执行

这里粘一下PageInfo属性具体含义

private int pageNum;//当前页

private int pageSize;//每页的数量

private int size;//当前页的数量

private int startRow;//分页后开始行

private int endRow;//分页后结束行

private int startRow;//当前页面第一个元素在数据库中的行号

private int endRow;//当前页面最后一个元素在数据库中的行号

private long total;//总记录数

private int pages;//总页数

private List list;//结果集(每页显示的数据)

private int firstPage;//第一页

private int prePage;//前一页

private boolean isFirstPage = false;//是否为第一页

private boolean isLastPage = false;//是否为最后一页

private boolean hasPreviousPage = false;//是否有前一页

private boolean hasNextPage = false;//是否有下一页

private int navigatePages;//导航页码数

private int[] navigatepageNums;//所有导航页号

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