【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")
相关推荐
霸道流氓气质14 小时前
SpringBoot中调用mybatis方法提示映射文件未找到Invalid bound statement(not found)的奇葩解决
spring boot·后端·mybatis
一只大袋鼠14 小时前
MyBatis 从入门到实战(二):代理 Dao 开发与多表关联查询
java·开发语言·数据库·mysql·mybatis
tycooncool18 小时前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
隐退山林19 小时前
JavaEE进阶:Spring Web MVC入门(1)
前端·spring·java-ee
一只大袋鼠1 天前
MyBatis 入门详细实战教程(一):从环境搭建到查询运行
java·开发语言·数据库·mysql·mybatis
Full Stack Developme2 天前
MyBatis-Plus 流式查询教程
前端·python·mybatis
ccice012 天前
全面掌握Spring Boot + MyBatis + Maven + MySQL:从开发到部署的后端技术详解
spring boot·maven·mybatis
消失的旧时光-19432 天前
Spring Boot + MyBatis 从 0 到 1 跑通查询接口(含全部踩坑)
spring boot·后端·spring·mybatis
阿拉金alakin2 天前
深入理解 Java 线程池:核心参数、工作流程与常用创建方式
java·开发语言·java-ee
1.14(java)2 天前
MyBatis 操作数据库
数据库·mybatis