Mybatis进行多条件查询之where标签
where:
当where标签中有内容时,会自动生成where关键字,并且将内容前多余的and或or去掉
当where标签中没有内容时,此时where标签没有任何效果
注意:where标签不能将内容前的and去掉
1.接口类中的文件和上一篇文章一致 映射文件中的内容
<!--List<Emp> getEmpByCondition(Emp emp);-->
<select id="getEmpByCondition" resultType="emp">
select * from t_emp
<where>
<if test="empName!=null and empName !=''">
emp_name=#{empName}
</if>
<if test="age!=null and age !=''">
age=#{age}
</if>
<if test="sex!=null and sex !=''">
sex=#{sex}
</if>
<if test="email!=null and email !=''">
email=#{email}
</if>
</where>
</select>