SpringBoot+MyBatis使用PageHelper分页

POM文件导入依赖

<!-- PageHelper使用 -->
        <!--分页-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.10</version>
        </dependency>

yml中配置:

pagehelper:
  reasonable: true
  support-methods-arguments: true
  params: count=countSql

Param:

@Data
public class AuctionParam {
    int auctionId;
    /**当前页数*/
    int page;         
    /**本页条数*/
    int size;         
}

Controller:

 /**
     * 根据场次id获取场次中的商品
     * 贺庆玉
     * @return
     */
    @PostMapping(value = "getCommodityAuction")
    public Result getCommodityAuction(@RequestBody AuctionParam param){

        PageHelper.startPage(param.getPage(),param.getSize());
        List<CommodityAuction> list = commodityAuctionService.getCommodityAuction(param.getAuctionId());

        //PageInfo就是一个分页Bean
        PageInfo<CommodityAuction> pageInfo =new PageInfo<>(list);

        return Result.ok("list",pageInfo);
    }

你可能感兴趣的:(SpringBoot+MyBatis使用PageHelper分页)