Mybatis的test字符串比较
使用<choose>标签
如:
<choose> <when test="query.auditType != null and query.auditType == '2'"> AND ci.audit_status = '2' </when> <otherwise> AND ci.audit_status IN ('0', '3') </otherwise>
</choose>
你会发现它一直执行的是<otherwise>内的
如果要正确执行
方法一:
需要在'2' 加上.toString()
如:
<choose>
<when test="query.auditType != null and query.auditType == '2'.toString()">
AND ci.audit_status = '2'
</when>
<otherwise>
AND ci.audit_status IN ('0', '3')
</otherwise>
</choose>
方法二:外层使用单引号,内层使用双引号
<choose>
<when test='query.auditType != null and query.auditType == "2"'>
AND ci.audit_status = '2'
</when>
<otherwise>
AND ci.audit_status IN ('0', '3')
</otherwise>
</choose>
浙公网安备 33010602011771号