<!--List<Emp> getEmpListByCondition(Emp emp);--><selectid="getEmpListByMoreTJ"resultType="Emp">
select * from t_emp where 1=1
<iftest="ename != '' and ename != null">
and ename = #{ename}
</if><iftest="age != '' and age != null">
and age = #{age}
</if><iftest="sex != '' and sex != null">
and sex = #{sex}
</if></select>
<selectid="getEmpListByMoreTJ2"resultType="Emp">
select * from t_emp
<where><iftest="ename != '' and ename != null">
ename = #{ename}
</if><iftest="age != '' and age != null">
and age = #{age}
</if><iftest="sex != '' and sex != null">
and sex = #{sex}
</if></where></select>
<selectid="getEmpListByMoreTJ"resultType="Emp">
select * from t_emp
<trimprefix="where"suffixOverrides="and"><iftest="ename != '' and ename != null">
ename = #{ename} and
</if><iftest="age != '' and age != null">
age = #{age} and
</if><iftest="sex != '' and sex != null">
sex = #{sex}
</if></trim></select>
④choose、when、otherwise解决选择单个条件
即choose内部只会有一个条件被添加则where后面(满足则跳出)
<!--List<Emp> getEmpListByChoose(Emp emp);--><selectid="getEmpListByChoose"resultType="Emp">
select <includerefid="empColumns"></include> from t_emp
<where><choose><whentest="ename != '' and ename != null">
ename = #{ename}
</when><whentest="age != '' and age != null">
age = #{age}
</when><whentest="sex != '' and sex != null">
sex = #{sex}
</when><whentest="email != '' and email != null">
email = #{email}
</when></choose></where></select>