做分页查询要有两步:
第一步,设置MyBatisPlus配置类
package com.gsoft.demo.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.*;
/**
* MyBatisPlus配置类
* @author Administrator
*/
@Configuration
public class MyBatisPlusConfig {
/**
* MyBatisPlus拦截器(用于分页)
*/
@Bean
public MybatisPlusInterceptor paginationInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//添加MySQL的分页拦截器
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.SQLITE));
return interceptor;
}
}
第二步:在service层里进行分页
@Override
public Page getListByPage(int current, int size) {
Page<SwaggerEntity> entityPage = new Page<>(current, size);
QueryWrapper<SwaggerEntity> wrapper = new QueryWrapper<>();
Page<SwaggerEntity> swaggerEntityPage = swaggerMapper.selectPage(entityPage, wrapper);
return swaggerEntityPage;
}