1.判断Double类型:
<if test="probability != null">
probability = #{probability},
</if>
//在实体类中probability字段是Double类型;
2.判断Integer类型:
<if test="faceValue != null">
face_value = #{faceValue},
</if>
//在实体类中faceValue字段是Integer类型;
3.判断String类型:
<if test="couponName != null and couponName != ''">
coupon_name = #{couponName},
</if>
//在实体类中couponName是String类型;
4.判断Date类型:
<if test="beginTime != null">
begin_time = #{beginTime},
</if>
//在实体类中beginTime字段是Date类型;
5.判断集合或者数组
<if test="hymap != null and hymap.size() != 0">
and t.hy_name not in
<foreach collection="hymap" item="item1" open="(" close=")" index="i" separator=",">
#{item1,jdbcType=VARCHAR}
</foreach>
</if>
总结:
Integer类型数据,如果变量的值是0,即faceValue = 0, mybatis在进行 faceValue != ''
判断的时候会认为faceValue的值是空字符串, 即判断faceValue == ''为true;Double、Date模式相同。
所以如果判断的数据是Integer、Double、Date类型只需要判断 != null 即可。
另外,如果String类型需要判断不等于0,则需要写name != '0'.toString(),否则会报错