mybatisHelper usage

Implement paging functionality requires three steps: The first step, calling startPage PageHelper method, passing in the number of pages and each page is displayed; the second step, filling paged data; The third step is to start paging. Note that all collections are processed with List

public ServerResponse<PageInfo> getProductList(int pageNum, int pageSize) {
        //1.startPage--start
        PageHelper.startPage(pageNum,pageSize);
        //2.填充自己的sql查询逻辑
        List<Product> productList = productMapper.selectList();

        List<ProductListVo> productListVoList = Lists.newArrayList();
        for (Product productItem : productList) {
            ProductListVo productListVo = assembleProductListVo(productItem);
            productListVoList.add(productListVo);
        }
        //3.pageHelper--收尾
        PageInfo pageResult = new PageInfo(productList);
        //分页结果重置
        pageResult.setList(productListVoList);
        return ServerResponse.createBySuccess(pageResult);
    }
    //productListVo的组装方法
    private ProductListVo assembleProductListVo(Product product){
        ProductListVo productListVo = new ProductListVo();
        productListVo.setId(product.getId());
        productListVo.setName(product.getName());
        productListVo.setCategoryId(product.getCategoryId());
        productListVo.setImageHost(PropertiesUtil.getProperty("ftp.server.http.prefix","http://img.liuhe.link/"));
        productListVo.setMainImage(product.getMainImage());
        productListVo.setPrice(product.getPrice());
        productListVo.setSubtitle(product.getSubtitle());
        productListVo.setStatus(product.getStatus());
        return productListVo;
    }

No written PageInfo pageResult = new PageInfo (productListVoList) ; reason is PageHelper
is AOP to do, so if out of the target, cut does not hit, then pagehepler automatic increase in the limit and offset sql etc it does not get on it

Reproduced in: https: //www.jianshu.com/p/48d768fd9f0c

Guess you like

Origin blog.csdn.net/weixin_34313182/article/details/91052237