LambdaQueryWrapper 的列名匹配使用的是“Lambda的语法,偏向于对象”
public Page<Merchants> List(MerchantRequest info) {
LambdaQueryWrapper<Merchant> queryWrapper = new LambdaQueryWrapper<>();
// 模糊搜索条件
if (StringUtils.notEmpty(info.getKeyword())) {
queryWrapper.and(c -> c.like(Merchant::getMallName, info.getKeyword())
.or().like(Merchant::getOwnerId, info.getKeyword())
.or().like(Merchant::getOwnerName, info.getKeyword()));
}
// 时间范围查询
if (StringUtils.notEmpty(info.getCreateTimeStart()) && StringUtils.notEmpty(info.getCreateTimeEnd())) {
queryWrapper.ge(Merchant::getCreateTime, info.getCreateTimeStart());
queryWrapper.le(Merchant::getCreateTime, info.getCreateTimeEnd());
}
// 排序条件
if (StringUtils.notEmpty(info.getSort()) && StringUtils.notEmpty(info.getOrder())) {
// sort ---> "create_time" , order -> desc,asc
queryWrapper.last(" order by ".concat(info.getSort()).concat(" ").concat(info.getOrder()));
}
return merchantService.page(new Page<>(info.getPage(), info.getSize()), queryWrapper);
}