美文网首页
Springboot集成PageHeaper分页

Springboot集成PageHeaper分页

作者: 白云的离殇 | 来源:发表于2020-04-08 21:12 被阅读0次

1.首先在maven中添加pageheaper依赖

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.13</version>
        </dependency>

2.添加返回数据的业务代码

  /**
     * 查看所有商品
     * @param productInfo
     * @return
     */
    List<ProductInfo> queryAll(ProductInfo productInfo);

所用到查询的sql语句:

  <select id="queryAll" resultMap="ProductInfoMap">
        select
          product_id, product_name, product_price, product_stock, product_description, product_icon, category_type, create_time, update_time, product_status
        from elm.product_info
        <where>
            <if test="productId != null">
                and product_id  like concat('%', #{productId}, '%')
            </if>
            <if test="productName != null and productName != ''">
                and product_name like concat('%', #{productName}, '%')
            </if>
            <if test="productDescription != null and productDescription != ''">
                and product_description like concat('%', #{productDescription}, '%')
            </if>
        </where>
    </select>

3.在Controller中使用

    @ApiOperation(value = "获取所有商品", notes = "可选参数pageNum:当前页码,默认为1,可选参数pageSize:页面大小,默认为6;")
    @GetMapping("/getall")
    public Result getall(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                         @RequestParam(required = false,defaultValue = "6") Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ProductInfo> list = productInfoService.queryAll(null);
        PageInfo<ProductInfo> pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }

4.返回结果
返回参数介绍

     //当前页
    private int pageNum;
    //每页的数量
    private int pageSize;
    //当前页的数量
    private int size;
    //由于startRow和endRow不常用,这里说个具体的用法
    //可以在页面中"显示startRow到endRow 共size条数据"
    //当前页面第一个元素在数据库中的行号
    private int startRow;
    //当前页面最后一个元素在数据库中的行号
    private int endRow;
    //总记录数
    private long total;
    //总页数
    private int pages;
    //结果集(每页显示的数据)
    private List<T> 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;

本实例结果


返回结果

相关文章

网友评论

      本文标题:Springboot集成PageHeaper分页

      本文链接:https://www.haomeiwen.com/subject/bxmxmhtx.html