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;
/**
* MyBatisPlus的分页配置
*/
@Configuration
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
//1,定义Mp拦截器
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
//2,添加具体的拦截器,这里添加的为分页拦截器
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return mybatisPlusInterceptor;
}
}
mybatis-plus物理分页的坑
分页查询带删除的时候页码会左移,也就是查询的时候只能查到1,3,5,7,9
解决办法:不使用分页直接limit查询
LambdaQueryWrapper<WxCpMakeUpSeq> wrapper = Wrappers.lambdaQuery(WxCpMakeUpSeq.class)
.eq(WxCpMakeUpSeq::getSeqEsState, 1).last(" limit " + size);
在使用MyBatisPlus进行分页查询时,如果结合删除操作,可能会遇到页码会左移的问题,即查询结果只显示奇数页。为解决这个问题,文章提出了一个替代方案,即不使用分页拦截器,而是通过LambdaQueryWrapper配合`last(limit+size)`来限制查询结果的数量。
2965

被折叠的 条评论
为什么被折叠?



