mybatis-plus pageHelper 合理化配置

mybatis 分页设置

// 自定义分页拦截器
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;

public class CustomPaginationInterceptor extends PaginationInnerInterceptor {
    @Override
    protected void handlerOverflow(IPage<?> page) {
        //原来的逻辑是超出范围返回第一页
        //page.setCurrent(1L);

        //修改成返回最后一页
        page.setCurrent(page.getPages());
    }
}


// 注册拦截器
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.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class MyBatisPlusConfig {


    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.KINGBASE_ES);
        // 设置最大单页限制数量,默认 500 条,-1 不受限制
        paginationInnerInterceptor.setMaxLimit(-1L);
        // 分页合理化
        paginationInnerInterceptor.setOverflow(true);
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }

}

 

posted @ 2024-05-13 10:14  ジ绯色月下ぎ  阅读(104)  评论(0编辑  收藏  举报