mybatis mapper判断if条件写法

//1 mybatis处理不同字符串
String s1 = null, s2 = "";
// mapper对于这两种情况判断不同,下面语句可以排除这两种情况
<if test="str != null and str != ''"></if>

//2 判断集合时候为空
if test="arr != null and arr.size > 0"></if>

//3 判断数字大于0
<if test="num != null and num gt 0"></if>
<if test="num != null and num == 0"></if>

//4 判断字符串是否包含某字符
<if test="str.indexOf('abc') != -1"></if>

//5 判断字符串是否等于某字符
<if test="str != null and str == 'abc'.toString()"></if>
<if test='str != null and str == "abc"'></if>

//6 处理时间
<if test="date != null">
	DATE = #{date, jdbcType=DATE}
</if>

原文地址:https://www.cnblogs.com/paper-man/p/13284668.html