分页查询插件
旧版分页
@Configuration @EnableTransactionManagement //开启事务功能 @MapperScan("com.he.gulimall.product.dao") public class MyBatisConfig { //引入分页插件 @Bean public PaginationInterceptor paginationInterceptor(){ PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); //设置请求的页面大于最大页后操作,true调回到首页,false继续请求,默认false paginationInterceptor.setOverflow(true); //设置最大页限制数量,默认 500条,-1 不受限制 paginationInterceptor.setLimit(500); return paginationInterceptor; } }
①Mybatis-Plus依赖包:
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.2</version> </dependency>
②Mybatis-plus配置类:
@Configuration //@MapperScan("com.geesun.mapper")//扫描 持久层 接口 包 public class MybatisPlusConfig { /** * 启用MybatisPlus插件 * @return */ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor(){ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); //启用分页插件 interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); return interceptor; } }
③Controller使用
Page<实体类名字> page1 = new Page<>(1, 3); attrService.page(page1,"查询条件")
//构造条件
LambdaQueryWrapper<AttrEntity> wrapper = new LambdaQueryWrapper<AttrEntity>().eq(AttrEntity::getCatelogId, catelogId).notIn(AttrEntity::getAttrId, attrIds); String key = (String) params.get("key"); if (!StringUtils.isEmpty(key)){ wrapper.and((w) -> { w.eq(AttrEntity::getAttrId,key).or().like(AttrEntity::getAttrName,key); }); } IPage<AttrEntity> page = this.page(new Query<AttrEntity>().getPage(params), wrapper); PageUtils pageUtils = new PageUtils(page); return pageUtils;

浙公网安备 33010602011771号