1 List<TechnologyParamPackageMaterialVo> materialVoList = new ArrayList<>(); 2 3 LambdaQueryWrapper<TechnologyParamPackage> wrapper = new LambdaQueryWrapper<>(); 4 wrapper.eq(ObjUtil.isNotEmpty(queryReq.getStatus()),TechnologyParamPackage::getStatus,queryReq.getStatus()); 5 materialVoList.forEach(e ->{ 6 wrapper.or().eq(TechnologyParamPackage::getParamPackageCode,e.getParamPackageCode()) 7 .eq(TechnologyParamPackage::getParamPackageVersion,e.getParamPackageVersion()); 8 }); 9 wrapper.orderByDesc(TechnologyParamPackage::getCreateTime);
主要就是这个wrapper.or(),出来的效果为如下
1 SELECT 2 param_package_name, 3 param_package_version, 4 technology_code, 5 technology_version, 6 `STATUS` 7 FROM 8 technology_param_package 9 WHERE 10 del_flag = '0' 11 AND ( 12 param_package_code = '002' 13 AND param_package_version = 2 14 OR param_package_code = 'package0603' 15 AND param_package_version = 603 16 OR param_package_code = 'packagecode03' 17 AND param_package_version = 3 18 OR param_package_code = 'devtest001' 19 AND param_package_version = 1 20 ) 21 ORDER BY 22 create_time DESC
这里记录主要是使用mybatisplus的LambdaQueryWrapper,里面的两个字段用and,之外用or去隔开
因为开发中用到多次,所以做个记录
第二个是如下:
if (StrUtil.isNotEmpty(queryReq.getSearchCodeAndName())){ wrapper.like(Maintenance::getMaintenanceCode,queryReq.getSearchCodeAndName()).or().like(Maintenance::getMaintenanceName,queryReq.getSearchCodeAndName()); }
效果如下
SELECT maintenance_code, maintenance_name, maintenance_period, maintenance_position, operation_method, standard FROM maintenance WHERE del_flag = '0' AND ( maintenance_code LIKE '%a%' OR maintenance_name LIKE '%a%' ) ORDER BY create_time DESC
这个是传入一个参数,查询两个字段,用or去区分隔开
标签:code,mybatisplus,package,param,入参,字段,version,wrapper,maintenance From: https://www.cnblogs.com/qwg-/p/18248333