Refactor: status to statuses using mybatis

Before:

<if test="status  = 0"> and t.status =  0 and  t.status1 = 1 </if>
<if test="status  = 1"> and t.status =  0 and  t.status2 = 2 </if>
<if test ="status != 2"> and t.status2 != 2 </if>

After:

<if test="statuses != null and statuses.size() > 0">
    and ( <foreach collection="statuses" item="status" separator=" OR ">
                <choose>
                    <when test="status == 0">
                        ( (t.status =  0 and  t.status1 = 1) and (t.status2 != 2) )
                    </when>
                    <when test="status == 1">
                        ( (t.status =  0 and  t.status2 = 2) and (t.status2 != 2) )
                    </when>
                    <otherwise>1 = 1</otherwise>
                </choose>
            </foreach>
            )
</if>

Points:

  1. seperator = “ OR ”

  2. Add () to each if statement

  3. Add otherwise to the end to prevent other exception