mybatis中使用 choose when otherwise 实现 if else 的判断逻辑,其中 when 对应 if,otherwise 对应 else,如下对应:
<choose>
<when test=""> // if 中的条件
//... // if 中执行的操作
</when>
<otherwise> // else 中的条件
//... // else 中执行的操作
</otherwise>
</choose>
示例:
<choose>
<when test="mainId != null and mainId != '' and mainId != 'undefined'">
AND MAIN_ID = #{mainId}
</when>
<otherwise>
AND OTHER_TEST = '0'
</otherwise>
</choose>