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 );
mybatis and 和or的使用
最新推荐文章于 2024-09-03 17:39:19 发布
该代码段展示了如何利用LambdaQueryWrapper对Recipe对象进行条件查询,包括等于(eq)操作、空检查(isNull)、Like操作以及排序(orderByDesc)。查询条件基于req对象的属性,并在某些条件下添加额外的过滤条件。最后,使用IPage进行分页查询。
摘要由CSDN通过智能技术生成