【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")
相关推荐
敲个大西瓜6 天前
mybatis拦截器插件实现数据库字段加解密
mybatis
我登哥MVP6 天前
SpringCloud Alibaba 核心组件解析:服务链路追踪
java·spring boot·后端·spring·spring cloud·java-ee·maven
武子康7 天前
Java-28 深入浅出 Spring 实现简易Ioc-04 在上节的业务下手动实现AOP
java·后端·mybatis
我命由我123457 天前
Jetpack Room - Room 查询返回列表无需判空、LIKE 关键字
android·java·开发语言·java-ee·android jetpack·android-studio·android runtime
一条泥憨鱼7 天前
苍穹外卖【day6|微信登录与商品浏览功能】
后端·mybatis·苍穹外卖
vx-Biye_Design7 天前
springboot安阳地区研学旅游服务小程序-计算机毕业设计源码12785
java·vue.js·windows·spring boot·tomcat·maven·mybatis
摇滚侠7 天前
MyBatis+Spring+SpringMVC SSM 整合 179-185
java·spring·mybatis
摇滚侠7 天前
MyBatis+Spring+SpringMVC SSM ContextLoaderListener 177-178
java·spring·mybatis
Spring小子7 天前
【Spring Boot + Vue + DeepSeek】从零打造一个AI驱动的智能健康分析系统
java·spring boot·mybatis