(英文缩写 + 中文含义 + 对应 SQL + 使用示例,直接对照复制就行)
一、等值 / 不等值条件
| 方法名 | 英文全称 | 中文含义 | 对应 SQL | 使用示例 |
|---|---|---|---|---|
| eq | equals | 等于 | = | .eq("age", 18) |
| ne | not equals | 不等于 | != | .ne("gender", 1) |
| gt | greater than | 大于 | > | .gt("age", 20) |
| ge | greater than or equal | 大于等于 | >= | .ge("age", 18) |
| lt | less than | 小于 | < | .lt("age", 30) |
| le | less than or equal | 小于等于 | <= | .le("age", 60) |
| between | between | 在区间内 | between A and B | .between("age", 18, 30) |
| notBetween | not between | 不在区间内 | not between A and B | .notBetween("age", 18, 30) |
二、模糊查询 like
| 方法名 | 英文含义 | 对应 SQL | 说明 |
|---|---|---|---|
| like | 包含 | like '%值%' | .like("username", "zhang") |
| notLike | 不包含 | not like '%值%' | .notLike("username", "test") |
| likeLeft | 以...结尾 | like '%值' | 左边有百分号 |
| likeRight | 以...开头 | like '值%' | 右边有百分号 |
三、空值判断
| 方法名 | 中文含义 | 对应 SQL |
|---|---|---|
| isNull | 字段为 NULL | is null |
| isNotNull | 字段不为 NULL | is not null |
四、集合查询 in / not in
| 方法名 | 中文含义 | 对应 SQL | 使用示例 |
|---|---|---|---|
| in | 在列表中 | in (...) | .in("id", List.of(1,2,3)) |
| notIn | 不在列表中 | not in (...) | .notIn("id", List.of(4,5,6)) |
五、逻辑条件 and / or
| 方法名 | 作用 | 使用场景 |
|---|---|---|
| and | 并且(默认连接就是 and) | 多条件直接链式调用 |
| or | 或者 | 拼接 or 条件,会自动加括号 |
| nested | 嵌套条件 | 用于复杂括号分组 |
六、排序
| 方法名 | 作用 | 示例 |
|---|---|---|
| orderByAsc | 升序排序 | .orderByAsc("age", "id") |
| orderByDesc | 降序排序 | .orderByDesc("create_time") |
七、Lambda 写法对照(推荐)
普通写法:
java
.eq("user_id", 1)
.like("username", "min")
Lambda 写法(不易写错):
java
.eq(UserInfo::getUserId, 1)
.like(UserInfo::getUsername, "min")