乐趣区

关于java:Mybatisplus条件构造器QueryWrapper

Mybatisplus 条件结构器 QueryWrapper

QueryWrapper:Entity 对象封装操作类
LambdaQueryWrapper:用于 Lambda 语法应用的查问 Wrapper

例:

        QueryWrapper<User> queryWrapper = QueryGenerator.initQueryWrapper(user,null);
        queryWrapper.eq("user_name",user.getUserName());
        IPage<User> page = new Page<>(pageNo, pageSize);
        IPage<User> pageList = userServer.page(page, queryWrapper);

例:

 protected FrfReptPlan getFrfReptPlan(String contractId,String perdNum,String costType){return frfReptPlanService.getOne(new LambdaQueryWrapper<FrfReptPlan>()
        .eq(FrfReptPlan::getFpfContrId, contractId)
        .eq(FrfReptPlan::getPerdNum, perdNum)
        .eq(FrfReptPlan::getCostType,costType));
}

罕用办法:

 办法          形容            等价             例子
eq            等于            =               eq("name","吕布")name="吕布"
ne            不等于          <>              ne("name","吕布") 含意:name<>"吕布"
gt            大于            >               gt("age","10") 含意:age>10
lt            小于            <               lt("age","10") 含意:age<10
ge            大于等于        >=              ge("age","10") 含意:age>=10
le            小于等于        <=              le("age","10") 含意:age<=10
between       在值 1 值 2 之间    between and     between("age","10","18") 含意:10<=age<=18
notBetween    不在值 1 值 2 之间 not bteween and  notBetween("age","10","18") 含意:18<age 或 age<10
like          含糊查问        like            like("name","吕") 含意:name like "% 吕 %"
notLike       含糊查问        not Like        notLike("name","吕") 含意:name not like "% 吕 %"
likLeft       含糊查问                        likLeft("name","吕") 含意:name like "% 吕"
likeRight     含糊查问                        likeRight("name","吕") 含意:name like "吕 %"
isNull        是否为空
isNotNull     字段为不空
in            in             in               age in (10,15,20) 含意:age 在 10,15,20 之间
notIn         not  in        not  in          age not in (10,15,20) 含意:age 不在 10,15,20 之间
inSql         in(sql)                         inSql("id","select id from table") 含意:id in (select id from table)
notInSql      not in(sql)                     notInSql("id","select id from table") 含意:id not in (select id from table)
groupBy       分组           group by         groupBy(id,name) 含意:group by id,name
orderByAsc    升序                            orderByAsc(id,name) 含意:order by id asc,name asc
orderByDesc   降序                            orderByDesc(id,name) 含意:order by id desc,name desc
orderBy       排序           order by         orderBy(true,true,"id","name") 含意:order by id asc,name asc
having        having
or            或             or               eq("id","1") or eq("id","2") 含意:id='1' or id='2'
and           且             and              eq("id","1") and eq("id","2") 含意:id='1' and id='2'
apply         拼接 sql
last          忽视优化规定间接拼接 sql 最初
exists        拼接
notExists     拼接
nested        失常嵌套,不带 and 或者 or
退出移动版