在一般情况下,我们会使用<if></if>标签对传入值进行非空判断,但是不同类型的数据判断方法会不一样。
1.数字类型和字符串:
<if test = "game.gameName != null and game.gameName !='' ">
and g.game_name LIKE CONCAT('%',#{game.gameName},'%')
</if>
会判断是否为null和空字符。
2.日期类型:
<if test = "null != game.gmtCreate">
and g.gmt_create >= #{game.queryBeginTime} and g.gmt_create < #{game.queryEndTime}
</if>
日期类型只能判断是否为空,如果判断空字符则会报错。
3.数组类型:
<if test="null != gameIds and gameIds.size > 0">
and b.gameid in
<foreach collection="gameIds" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
判断是否为空,和其size是否大于0