choose--when--otherwise:相当于if...else if...else
(与if标签的区别:用if时,条件都要执行,choose,when,otherwise只要一个满足条件后面就不再执行因此不需要and)
<select id="getEmpBycondition" resultType="Emp">
select*from t_emp
<trim prefix=where>
<choose>
<when test="empName != null and empName != ''">
emp_name =#{empName}
</when>
<when test="age != null and age != "'">
age = #{age}
</when>
<when test="empName != null and empName != ''">
emp_name =#{ empName}
</when>
<otherwise>
id=1
</otherwise>
</choose>
</trim>
</select>
网友评论