mybatis 数据库字段为空or为空串 忽略条件过滤, 不为空且不为空串时才需nameParam过滤条件

name未配置视为不考虑name条件

select * from user where (( (ISNULL(name)) OR (name='') ) OR name = #{user.nameParam} )

三个or语句 推荐这个

select * from user where ISNULL(name) OR name='' OR name = #{user.nameParam}

sql 复制代码
select * from user where ISNULL(name) OR name=''
<if test="user.nameParam != null and user.nameParam !=''">
OR name = #{user.nameParam}
</if>

数据库的name字段为空或为空字符串 ,nameParam 无论有无值都可以匹配到

数据库的name字段不为空也不为空字符串, 就要用nameParam匹配了(传参nameParam不为空, 和数据库的不为空的匹配; 传参nameParam为空, 数据库的为空的匹配, 即不考虑name条件的场景)

相关推荐
-SGlow-4 小时前
MySQL相关概念和易错知识点(3)(表内容的CURD、内置函数)
linux·运维·服务器·数据库·mysql
飞翔的佩奇4 小时前
基于SpringBoot+MyBatis+MySQL+VUE实现的经方药食两用服务平台管理系统(附源码+数据库+毕业论文+部署教程+配套软件)
数据库·vue.js·spring boot·mysql·毕业设计·mybatis·经方药食两用平台
bing_1585 小时前
在多租户或多服务共享 Redis 时,如何做逻辑隔离或权限控制?
数据库·redis·缓存
ChaITSimpleLove5 小时前
PostgreSQL 中删除指定数据库下的所有表结构
数据库·postgresql·bash·sql 脚本·.net npgsql
孫治AllenSun7 小时前
【Mysql】字段隐式转换对where条件和join关联条件的影响
数据库·mysql·oracle
生涯にわたる学び7 小时前
数据库02 网页html01 day44
数据库·html
2301_793086878 小时前
Mysql group by
数据库·mysql
jllllyuz8 小时前
Spring中的事务是如何实现的
数据库·sql·spring
wangmengxxw8 小时前
Spring-常用注解
java·数据库·spring·注解
m0_747266099 小时前
contentprovider实验+SQLite数据库的实现
数据库·sqlite