Wrapper<Student> queryWrapper = Wrappers.<Student>lambdaQuery()
.in(ObjectUtil.isNotEmpty(stuList), Student::getStuId, stuList);
return uCityClubMapper.selectList(queryWrapper);
或者是如下:
QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
Student stu = new Student();
queryWrapper
.in(!stuIdList.isEmpty(), "数据库字段",stuIdList)
.eq(Objects.nonNull(stu.getName()), "数据库字段", stu.getName());
queryWrapper.lambda().orderByDesc(Student::getCreateTime);
return this.list(queryWrapper);
常用函数
函数 | 说明 | 例子(以下为where后的条件,select * from user where ?) |
---|---|---|
eq | 等于= | eq("name","张三") --> name = '张三' |
ne | 不等于 != | ne("name","李四") --> name != '李四' |
gt | 大于 > | gt(age,18) --> age > 18 //年龄大于18岁 |
ge | 大于等于 >= | ge(age,18) --> age >=18 |
lt | 小于 < | lt(age,20) --> age < 20 //年龄小于20岁 |
le | 小于等于 <= | le(age,20) ---> age <= 20 |
between | between 值1 and 值2 | between(age,15,25) ---> 匹配15岁到25岁之间(包含15和25) |
nobetween | not between 值1 and 值2 | notBetween(age,35,45)-->匹配不包含35-45之间的(包含35和45) |
like | like '%值%' | like("name","张") --> like '%张%' |
notlike | not like '%值%' | notLike("name”,"张") --> not like '%张%' |
likeLeft | like '%值' | likeLeft("name","王") ---> like "%王" |
likeRight | like '值%' | likeRight("name","王") ---> like "王%" |
isNull | 表字段 is NULL | isNull("name") ---> name is null |
notNull | 表字段 is not NULL | isNull("name") ---> name is not null |
in | 表字段in(v1,v2,v3...) | in("num",{1,2,3}) ---> num in (1,2,3) |
notIn | 表字段 not in(v1.v2,v3) | notIn("num",{2,3,4}) ---> num not in (2,3,4) |