The use of mybatisplus paging plug in


#Mybatisplus version requirements: 3.4 and above

First, create a new accessory file

public class MybatisConfig implements MetaObjectHandler{

    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
        return interceptor;

Using in controller or service layer

Default to the first page, 10 items per page

    public RestResult list(@RequestParam(defaultValue = "1") int current,@RequestParam(defaultValue = "10") int size){"list");
        long userId = BaseController.getUserId();
        QueryWrapper<Charge> queryWrapper = new QueryWrapper<>();
        IPage<Charge> iPage = new Page<>(current,size);
        IPage<Charge> list =,queryWrapper);

        return RestResult.success(list);



Page class parameters, with parameter constructor

public Page() {
        this.records = Collections.emptyList(); = 0L;
        this.size = 10L;
        this.current = 1L;
        this.orders = new ArrayList();
        this.optimizeCountSql = true;
        this.isSearchCount = true;
        this.hitCount = false;

    public Page(long current, long size) {
        this(current, size, 0L);

This work adoptsCC agreementReprint must indicate the author and the link of this article