mybatis 遇到空串无法判断
sql 语句中对传入的关键字进行判断,如果是空或者空串则不进入条件
<if test="query.keyword !=null and query.keyword != ''"> and (t.id like concat('%',#{query.keyword},'%') or t.trading_account_id like concat('%',#{query.keyword},'%') or u.fx_code like concat('%',#{query.keyword},'%') or a.account_name like concat('%',#{query.keyword},'%') ) </if>
而实际上,当传入
数据库执行情况
==> Preparing: SELECT count(0) FROM t_trading_announcement t LEFT JOIN t_trading_account a ON a.id = t.trading_account_id LEFT JOIN t_user u ON u.id = a.user_id
WHERE 1 = 1 AND (t.id LIKE concat('%', ?, '%') OR t.trading_account_id LIKE concat('%', ?, '%') OR u.fx_code LIKE concat('%', ?, '%') OR a.account_name LIKE concat('%', ?, '%')) ==> Parameters: ''(String), ''(String), ''(String), ''(String) <== Columns: count(0) <== Row: 0 <== Total: 1
判断失效,原因还没找到。暂时代码中判断
如果传入 “” ,则可以通过判断
如果传入的是 ‘’ ,则接收的参数实际上是 “‘’”