Mybatis-plus如何使用
Service内获取分页信息
public PageInfo<Purchase> pageInfo(PurchaseParam purchaseParam) {
PageHelper.startPage(purchaseParam.getPageNum(), purchaseParam.getPageSize());
List<Purchase> purchases = purchaseMapper.getPageInfo(purchaseParam);
//用PageInfo对结果进行包装
PageInfo<Purchase> page = new PageInfo<>(purchases);
//设值行号
AtomicInteger atomicInteger = new AtomicInteger(1);
int rowNumStart = (purchaseParam.getPageNum() - 1 * purchaseParam.getPageSize());
page.getList().forEach(purchase -> purchase.setRowNum(rowNumStart + (atomicInteger.getAndIncrement())));
return page;
}
查询
第一种方式
List<PurchaseDetail> purchaseDetails = new LambdaQueryChainWrapper<PurchaseDetail>(purchaseDetailService.getBaseMapper())
.eq(PurchaseDetail::getUserId, purchase.getId())
.list();
第二种方式
QueryWrapper<PurSupplierRange> queryWrapper = Wrappers.query();
queryWrapper.eq("USER_ID", userId);
List<PurSupplierRange> purSupplierRanges = supplierRangeService.list(queryWrapper);
if (CollectionUtil.isNotEmpty(purSupplierRanges)) {
purchase.setPurSupplierR