springboot项目快速分页操作
mybaties-plus自从springboot依赖开始,分页实现就比较快捷:
1.第一步就是直接service 继承
2.
BasePageRequest:
package com.hbg.common.model.base; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data @ApiModel("分页参数") public class BasePageRequest { @ApiModelProperty(value = "当前页码", required = true) private Integer pageNo; @ApiModelProperty(value = "每页条数", required = true) private Integer pageSize; public int getPageNo() { if(pageNo == null || pageNo <= 0){ pageNo = 1; } return pageNo; } public int getPageSize() { if(pageSize == null || pageSize <= 0){ pageSize = 10; } return pageSize; } @ApiModelProperty(hidden = true) public <T> Page<T> getPage() { return new Page<>(getPageNo(), getPageSize()); } }
实现调用:
public Page<CardVoucherResponse> findAllCardVoucher(BasePageRequest request) { Page<CardVoucher> cardVoucherList = cardVoucherManager.page(request.getPage(), new LambdaQueryWrapper<CardVoucher>().eq(CardVoucher::getCardType, Integer.valueOf(0)) .eq(CardVoucher::getIsShow, 1).orderByDesc(CardVoucher::getCreateTime)); List<CardVoucher> list = Lists.newArrayList(); for (CardVoucher cardVoucher : cardVoucherList.getRecords()) { if (cardVoucher.getEndTime().isBefore(LocalDateTime.now())) { cardVoucher.setCardType(1); list.add(cardVoucher); } }
public IPage<CardVoucher> getPageList(Integer pageNo, Integer pageSize, Integer cardType, String type,String keyWords) { QueryWrapper<CardVoucher> wrapper = new QueryWrapper<>(); if(cardType!=null&&!StringUtils.isEmpty(cardType.toString())){ wrapper.eq("card_type", cardType); } if(type!=null&&!("").equals(type)){ wrapper.eq("type", type); } if(keyWords!=null&&!StringUtils.isEmpty(keyWords)){ wrapper.like("coupon_name",keyWords); } wrapper.orderByDesc("create_time"); //wrapper.eq("card_type",0); return baseMapper.selectPage(new Page<>(pageNo, pageSize), wrapper); }
                    
                
                
            
        
浙公网安备 33010602011771号