/** * 素材列表查询 * @param dto * @return */ @Override public ResponseResult findList(WmMaterialDto dto) { //1、检查参数 dto.checkParam(); //2、分页查询 IPage page = new Page<>(dto.getPage(), dto.getSize()); LambdaQueryWrapper<WmMaterial> lambdaQueryWrapper = new LambdaQueryWrapper<>(); //是否收藏 if(dto.getIsCollection() != null && dto.getIsCollection() == 1){ lambdaQueryWrapper.eq(WmMaterial::getIsCollection, dto.getIsCollection()); } //按照用户查询 lambdaQueryWrapper.eq(WmMaterial::getUserId, WmThreadLocalUtil.getUser().getId()); //按照时间倒叙插叙 lambdaQueryWrapper.orderByDesc(WmMaterial::getCreatedTime); page = page(page, lambdaQueryWrapper); //3、返回 ResponseResult responseResult = new PageResponseResult(dto.getPage(), dto.getSize(), (int)page.getTotal()); responseResult.setData(page.getRecords()); return responseResult; }
添加分页拦截器
package com.heima.wemedia; import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.context.annotation.Bean; @SpringBootApplication @EnableDiscoveryClient @MapperScan("com.heima.wemedia.mapper") public class WemediaApplication { public static void main(String[] args) { SpringApplication.run(WemediaApplication.class,args); } @Bean public MybatisPlusInterceptor mybatisPlusInterceptor(){ MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor(); mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); return mybatisPlusInterceptor; } }
标签:lambdaQueryWrapper,dto,分页,org,图片素材,素材,new,import,page From: https://www.cnblogs.com/fxzm/p/17511944.html