1、where与if标签
<select id="selectStudentByConditionByWhere" resultType="Student">
select id,name,age,scorefrom tb_student
<where>
<if test="name != null and name != ''">
and name like '%' #{name} '%'
</if>
<if test="age > 0">
and age > #{age}
</if>
</where>
</select>
2、choose标签
<select id="selectStudentByConditionByChoose" resultType="Student">
select id,name,age,score
from tb_student
<where>
<choose>
<when test="name!=null and name!=''">
and name like '%' #{name} '%'
</when>
<when test="age > 0">
and age > #{age}
</when>
<otherwise>
1=2
</otherwise>
</choose>
</where>
</select>