JAVA代码
package com.tj.qywx.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tj.qywx.domain.WxBillList;
import com.tj.qywx.service.WxBillListService;
import com.tj.qywx.mapper.WxBillListMapper;
import com.tj.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
*/
@Slf4j
@Service
public class WxBillListServiceImpl extends ServiceImpl<WxBillListMapper, WxBillList>
implements WxBillListService{
@Override
public R show(Integer pagenum, Integer pagesize, WxBillList wxBillList) {
//构造条件构造器
LambdaQueryWrapper<WxBillList> lqw = new LambdaQueryWrapper();
//添加过滤条件
lqw.like(StringUtils.isNotEmpty(wxBillList.getPayeeName()), WxBillList::getPayeeName, wxBillList.getPayeeName());
//判断是否有分页
if (pagenum != null || pagesize != null) {
//构造分页构造器,
Page page = new Page(pagenum, pagesize);
//执行查询
page(page, lqw);
//如果查询后的pagenum(当前页码)>(实际的总页码),
if (pagenum > page.getPages()) {
log.info("当前页码>总的页码");
//那么当前页码就等于总页码,然后重新查询
page = new Page(page.getPages(), pagesize);
//执行查询
page(page, lqw);
}
log.info("查询到的page数据:{}", page.toString());
if (page.getTotal() > 0) {
return R.success(page);
} else {
return R.error("未查询到数据");
}
}
//2,不分页的查询,返回list
List<WxBillList> list = list(lqw);
log.info("查询到的list数据:{}", list.toString());
if (list != null) {
return R.success(list);
}
return R.error("未查询到数据");
}
}