参考文献:mybatis-plus 中 queryWrapper and多条件拼接_querywrapper 多条件-CSDN博客
目标sql:? SELECT idd,name,age,varchar1,varchar2,varchar3
?FROM t_test???WHERE (age = '哈哈' AND (idd = 2 OR name IN (1,2,3)));
lamda完整写法:
if(!StringUtils.isEmpty(key)){ wrapper.and((w)->{ w.eq("attr_id",key).or().like("attr_name",key); }); }
代码写法:
//根据value查询
@GetMapping("getTest")
public List<HashMap> getTest() {
LambdaQueryWrapper<TTest> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(TTest::getAge,"哈哈").
and(wrapper1-> wrapper1.eq(TTest::getIdd, 2).or().in(TTest::getName, 1,2,3));
List<TTest> list1 = testService.list(wrapper);
wrapper.clear();
wrapper.eq(TTest::getAge,"hehe");
List<TTest> list2 = testService.list(wrapper);
// testService.insertDemo(list1);
return new ArrayList<>();
}