if标签test为true时,才会执行语句,where标签自动判断是否为空,加减and、or
1.编写sql
<resultMap id="empMap" type="Employee">
<id property="id" column="id"/>
<result column="name" property="name"/>
</resultMap>
<select id="getEmpList" resultMap="empMap" parameterType="Employee">
SELECT id,name,birthday,dept,salary
FROM employee
<where>
<if test="name!=null">name=#{name}</if>
<if test="id!=null">and id=#{id}</if>
</where>
</select>
测试: