分页分页分页

public interface AdChannelService extends IService<AdChannel> {

    /**
     * 根据名称分页查询频道列表 
    PageResult<ChannelDto> findByPage(ChannelDto dto);
}

package com.heima.admin.service.impl; 

@Service
public class AdChannelServiceImpl extends ServiceImpl<AdChannelMapper, AdChannel> implements AdChannelService { 

   //获取用户id
        Integer uid = UserThreadLocalUtils.getUserId();
    @Override
    public PageResult<ChannelDto> findByPage(ChannelDto channelDto) {
//        构造分页条件
        Page<AdChannel> page = new Page(channelDto.getPage(),channelDto.getSize());
//        构造查询条件
        QueryWrapper<AdChannel> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(channelDto.getName())){
            queryWrapper.lambda().like(AdChannel::getName,channelDto.getName());
        }

 if (dto != null && dto.getStatus() != null) {
            queryWrapper.lambda().eq(ApUserAuth::getStatus, dto.getStatus());
        }

 queryWrapper.lambda().orderByDesc(WmMaterial::getCreatedTime);
//        分页查询1
        IPage<AdChannel> adChannelIPage = this.page(page, queryWrapper);
//        如果没有返回值

         分页查询2

//        设置分页条件
        IPage pageParam = new Page(dto.getPage(), dto.getSize());
//        分页查询
        IPage ipage = page(pageParam, queryWrapper);


        if(CollectionUtils.isEmpty(adChannelIPage.getRecords())){
            return null;
        }


        if(ipage == null || CollectionUtils.isEmpty(ipage.getRecords())){
            throw new LeadException(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        //            如果有返回值,对象转换
        List<ChannelDto> channelDtoList = BeanHelper.
                copyWithCollection(adChannelIPage.getRecords(), ChannelDto.class);
        return new PageResult<>(channelDto.getPage(),
                channelDto.getSize(),
                adChannelIPage.getTotal(),
                channelDtoList);
    }
}

package com.heima.admin.controller.v1; 

@RestController
@RequestMapping("/api/v1/channel")
public class ChannelController {

    @Autowired
    private AdChannelService channelService; 
    @PostMapping("/list")
    public PageResult<ChannelDto> findByPage(@RequestBody ChannelDto dto){
        return channelService.findByPage(dto);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值