1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
HashMap<SFunction<DemoMp, ?>, Object> params = new HashMap<>();
params.put(DemoMp::getCreateBy, "admin");
params.put(DemoMp::getUpdateBy, null);
String deptId = "1";
List<DemoMp> UserList = demoMpMapper.selectList(
// new QueryWrapper<DomainExample>().lambda()
new LambdaQueryWrapper<DemoMp>()
.select(DemoMp::getId, DemoMp::getSort, DemoMp::getCreateTime)
// .select(i -> i.getProperty().startsWith("test"))
// .select(DomainExample.class, i -> i.getProperty().startsWith("test"))
.allEq(true, params, false) // 参数3默认为true,false时不拼接"and update_by is null"
.allEq(true, (k, v) -> true, params, false) // 参数2:BiPredicate
.eq(true, DemoMp::getDeleted, 0L) // 等于
.ne(true, DemoMp::getDeleted, 1L) // 不等于
.gt(true, DemoMp::getDeleted, -1L) // 大于
.ge(true, DemoMp::getDeleted, -1L) // 大于等于
.lt(true, DemoMp::getDeleted, 9L) // 小于
.le(true, DemoMp::getDeleted, 9L) // 小于等于
.between(true, DemoMp::getCreateTime, LocalDateTime.now().minusYears(1), LocalDateTime.now().plusYears(1))
.notBetween(true, DemoMp::getCreateTime, LocalDateTime.now().minusYears(2), LocalDateTime.now().minusYears(1))
// Date类型 today筛选
.ge(DemoMp::getCreateTime, Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()))
.lt(DemoMp::getCreateTime, Date.from(LocalDateTime.now().plusDays(1).atZone(ZoneId.systemDefault()).toInstant()))
// LocalDateTime类型 today筛选
.ge(DemoMp::getCreateTime, LocalDate.now())
.lt(DemoMp::getCreateTime, LocalDate.now().plusDays(1))
.like(true, DemoMp::getCreateBy, "dm")
.notLike(true, DemoMp::getCreateBy, "不模糊匹配")
.likeLeft(true, DemoMp::getCreateBy, "min") // like '%min'
.notLikeLeft(true, DemoMp::getCreateBy, "左模糊") // like '%左模糊'
.likeRight(true, DemoMp::getCreateBy, "ad") // like 'ad%'
.notLikeRight(true, DemoMp::getCreateBy, "右模糊") // like '右模糊%'
.isNull(true, DemoMp::getSort) // sort is null
.isNotNull(true, DemoMp::getSort) // sort is not null
.in(true, DemoMp::getVersion, Arrays.asList(1L, 2L, 3L))
.in(true, DemoMp::getVersion, 1L, 2L, 3L)
.notIn(true, DemoMp::getVersion, Arrays.asList(9L, 9L, 9L))
.notIn(true, DemoMp::getVersion, 9L, 9L, 9L)
.inSql(true, DemoMp::getVersion, "1,5,7,7")
.inSql(true, DemoMp::getVersion, "select version from alice_tree where version > 0")
.notInSql(true, DemoMp::getVersion, "9,9")
.notInSql(true, DemoMp::getVersion, "select version from alice_tree where version < 0")
.groupBy(true, Arrays.asList(DemoMp::getId, DemoMp::getSort)) // group by id,sort
// .groupBy(true, DomainExample::getId, DomainExample::getSort)
.groupBy(true, DemoMp::getId)
.having(true, "sum(version) >= 1") // having sum(age) > 2 having必须跟groupBy一起使用
.having(true, "sum(version) > {0}", 2) // having sum(age) > 2 having必须跟groupBy一起使用
.and(true, i -> i.ne(true, DemoMp::getVersion, 0L).or().eq(true, DemoMp::getVersion, 1L)) // and 拼接
.or(true, i -> i.ne(true, DemoMp::getVersion, 0L).eq(true, DemoMp::getVersion, 1L)) // or 嵌套
.nested(true, i -> i.ne(true, DemoMp::getVersion, 0L).eq(true, DemoMp::getVersion, 1L)) // 正常嵌套 不带 AND 或者 OR (version <> 0 and version = 1)
.func(i -> {
if (true) {
i.eq(DemoMp::getId, 1L);
} else {
i.ne(DemoMp::getId, 1L);
}
}) // func 方法(主要方便在出现if...else下调用不同方法能不断链)
.apply(Objects.nonNull(deptId), "FIND_IN_SET ('" + deptId + "', ancestors )") // 拼接 sql {@link https://baomidou.com/pages/10c804/#apply)
.apply("date_format(create_time,'%Y-%m-%d') = '2023-03-24'")// date_format(creat_time,'%Y-%m-%d') = '2023-03-24'")
.last("limit 1") // 无视优化规则直接拼接到 sql 的最后, 只能调用一次,多次调用以最后一次为准 有sql注入的风险,请谨慎使用
.exists(true, "select id from table where age = 1") // exists (select id from table where age = 1)
.exists(true, "select id from table where age = {0}", 1) // exists (select id from table where age = 1)
.notExists(true, "select id from table where age = 1") // not exists (select id from table where age = 1)
.notExists(true, "select id from table where age = {0}", 1) // not exists (select id from table where age = 1)
.orderByAsc(true, Arrays.asList(DemoMp::getId, DemoMp::getSort))
// .orderByAsc(true, DomainExample::getId, DomainExample::getSort)
.orderByDesc(true, Arrays.asList(DemoMp::getId, DemoMp::getSort))
// .orderByDesc(true, DomainExample::getId, DomainExample::getSort)
.orderBy(true, true, Arrays.asList(DemoMp::getId, DemoMp::getSort)) // order by id ASC,sort ASC
// .orderBy(true, true, DomainExample::getId, DomainExample::getSort) // order by id ASC,sort ASC
.orderBy(true, true, Collections.singletonList(DemoMp::getId)));
|