QueryWrapper 条件选择器

满足条件1

select * from User where age = 10
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(User::getAge, userVo.getAge());

满足条件1和条件2

select * from User where status = 1 and age = 10
queryWrapper.and(queryWrapper1 -> queryWrapper1.eq("status",1).eq("age",userVo.getAge()));

满足条件1或者条件2

select * from User where status = 1 or age = 10
queryWrapper.or(queryWrapper1 -> queryWrapper1.eq("status",1));
queryWrapper.or(queryWrapper1 -> queryWrapper1.eq("age",userVo.getAge());

满足条件1和条件2 或者满足条件3

select * from User where (status = 1 and age = 10) or status = 2
queryWrapper.and(queryWrapper1 -> queryWrapper1.eq("status",1).eq("age",userVo.getAge()));
queryWrapper.or().eq("status",2);

满足条件1 或者 2 或者3 或者4 

select * from User where status = 1 or status = 2 or status = 3 or status = 4
StringBuffer workSQL = new StringBuffer("");
workSQL.append("(status = 1 or ");  
workSQL.append("(status = 2 or "); 
workSQL.append("(status = 3 or "); 
workSQL.append("(status = 4 or "); 
queryWrapper.lambda().and(queryWrapper1->queryWrapper1.apply(workSQL.substring(0,workSQL.length()-4)));

你可能感兴趣的:(java,服务器,后端,sql)