3.4.0之前版本
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
paginationInterceptor.setLimit(-1);
paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
return paginationInterceptor;
}
3.4.0之后版本
package com.zsatc.server.pim.bootstrap.config;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Slf4j
@Configuration
public class MybatisPlusConfig {
// 3.4.0 版本之后的分页配置方法
@Bean
public MybatisPlusInterceptor paginationInterceptor() {
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
//分页拦截器
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
paginationInnerInterceptor.setOverflow(false);
paginationInnerInterceptor.setMaxLimit(500L);
mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
// 设置请求的页面大于最大页后操作,true调回到首页,false继续请求默认false
// paginationInterceptor.setOverflow(false);//设置最大单页限制数量,默认500条,-1不受限制
// paginationInterceptor.setLimit(500);
// 开启 count 的 join 优化,只针对部分 left join
return mybatisPlusInterceptor;
}
@Bean
public ConfigurationCustomizer configurationCustomizer() {
return i -> i.setObjectWrapperFactory(new MybatisMapWrapperFactory());
}
@Bean
public IdentifierGenerator idGenerator() {
return new CustomIdGenerator();
}
// 获取long类型的id,雪花算法
private static final Snowflake SNOWFLAKE = IdUtil.getSnowflake(1, 1);
public class CustomIdGenerator implements IdentifierGenerator {
@Override
public Long nextId(Object entity) {
return SNOWFLAKE.nextId(); // BaseUtil.getNextId();
}
}
}
草稿版,待有空再完善该文章
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » MyBatisPlus 使用 IPage 分页
发表评论 取消回复