【JavaEE】MyBatis-Plus 条件构造器速查表

(英文缩写 + 中文含义 + 对应 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")
相关推荐
晚染烟4 小时前
每日八股day31
mybatis
MetaLite1 天前
MyBatis复杂SQL很灵活-自研ORM为何仍要保留SQL逃生口
java·mybatis
步行cgn1 天前
MyBatis 实现分页查询
mybatis
山甫aa1 天前
Javaweb---MyBatis增删改查
java·数据库·后端·mybatis·springboot
我命由我123452 天前
人脸识别 - 人脸识别选帧
java·人工智能·python·算法·安全·java-ee·人脸识别
choumou_M2 天前
SpringBoot_2:MyBatis-Generator插件使用教程
spring boot·tomcat·mybatis
SQL-First布道者2 天前
全面解构传统持久层框架,拥抱真正的 SQL-First
java·数据库·spring boot·sql·spring·mybatis·spring jdbc
重生之我是Java开发战士4 天前
【Java EE】Spring AOP :面向切面编程
java·spring·java-ee
晚安code4 天前
MyBatis-Plus 分页插件与字段自动填充:两行配置告别 CRUD 重复劳动
mybatis