mybatis and 和or的使用

该代码段展示了如何利用LambdaQueryWrapper对Recipe对象进行条件查询,包括等于(eq)操作、空检查(isNull)、Like操作以及排序(orderByDesc)。查询条件基于req对象的属性,并在某些条件下添加额外的过滤条件。最后,使用IPage进行分页查询。
摘要由CSDN通过智能技术生成
LambdaQueryWrapper<Recipe> lambdaQueryWrapper = new LambdaQueryWrapper<Recipe>()
      .eq(StringUtils.isNotEmpty(req.getEquipmentType()), Recipe::getEquipmentType, req.getEquipmentType())
      .eq(req.getRecipeType() != null, Recipe::getRecipeType, req.getRecipeType())
      .eq(StringUtils.isNotEmpty(req.getEquipmentId()), Recipe::getEquipmentId, req.getEquipmentId())
      .eq(req.getStatus() != null, Recipe::getStatus, req.getStatus())
      .eq(req.getType() != null, Recipe::getType, req.getType())
      .eq(req.getVersion() != null, Recipe::getVersion, req.getVersion())
      .eq(req.getGroupName() != null, Recipe::getGroupName, req.getGroupName())
      .eq(StringUtils.isNotEmpty(req.getConditionExt1()), Recipe::getConditionExt1, req.getConditionExt1())
      .eq(StringUtils.isNotEmpty(req.getConditionExt2()), Recipe::getConditionExt2, req.getConditionExt2())
      .eq("1".equals(req.getInfoExt5()), Recipe::getInfoExt5, "1")
      .isNull(Recipe::getParentId)

      .like(StringUtils.isNotEmpty(req.getRecipeName()), Recipe::getRecipeName, req.getRecipeName())
      .orderByDesc(Recipe::getStatus)
      .orderByDesc(Recipe::getCreateTime)
      .select(Recipe.class, i -> !i.getProperty().equals("body"));
if (!"1".equals(req.getInfoExt5())) {
   lambdaQueryWrapper.and(e->e.isNull(Recipe::getInfoExt5).or().eq(Recipe::getInfoExt5, "0"));
}
IPage<Recipe> page = recipeMapper.selectPage(new Page<>(req.getPageNo(), req.getPageSize()),
      lambdaQueryWrapper
);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值