单个if else
<select id="selectUserByState" resultType="com.bz.model.entity.User">
SELECT
*
FROM
user
WHERE
1=1
<choose>
<when test="state == 1">
AND name = #{name1}
</when>
<otherwise>
AND name = #{name2}
</otherwise>
</choose>
</select>
多个if elseif else
<select id="selectUserByState" resultType="com.bz.model.entity.User">
SELECT
*
FROM
user
WHERE
1=1
<choose>
<when test="state == 1">
AND name = #{name1}
</when>
<when test="state == 2">
AND name = #{name2}
</when>
<otherwise>
AND name = #{name3}
</otherwise>
</choose>
</select>