MyBatis Otherwise Tag: Usage Guide
In MyBatis, the
<select id="findUserById" resultType="User" parameterType="int">
SELECT * FROM user
WHERE id = #{id}
<choose>
<when test="id != null">
AND id = #{id}
</when>
<when test="username != null">
AND username = #{username}
</when>
<otherwise>
AND status = 1
</otherwise>
</choose>
</select>
In the example above, if the passed parameter is neither id nor username, the logic inside the