SQL语句当查询条件为空时默认查询全部数据,不为空是则按照条件进行查询

select * from 表 where (字段=条件 or 条件='')


当条件不为空时SQL语句等价于:select * from 表 where 字段=条件;

当条件为空时SQL语句等价于:select * from 表 where ''='';这样就实现了当查询条件为空时默认查询全部数据,当查询结果非空时则查询对应的数据。

edge:(where条件)

where f_name like '%${name}%' and (f_status=#{status} or #{status}='') and (f_data_node=#{dataNode} or #{dataNode}='') and (f_warehousing_scheme like '%${warehousingScheme}%' or '%${warehousingScheme}%' like '%%')")

猜你喜欢

转载自blog.csdn.net/Jiang5106/article/details/129795818