MySql当查询条件为空时不作为条件查询

问题遇到的现象和发生背景

在xml中怎么写sql判断前端传的三个字段进行联合查询,如果某一个字段为空,则不作为查询条件

问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

<select id="getPerson" resultType="com.test.bean.Employee">
    select * from tbl_employee
    <where>
        <!-- test:判断表达式(OGNL)
        遇见特殊符号应该去写转义字符:&&、''等字符
        -->
        <if test="id!=null">
            id=#{id}
        </if>
        <if test="lastName!=null and lastName!=''">
            and last_name like #{lastName}
        </if>
        <if test="email!=null and email.trim()!=''">
            and email=#{email}
        </if> 
        <!-- ognl会进行字符串与数字的转换判断  "0"==0 -->
        <if test="gender==0 or gender==1">
            and gender=#{gender}
        </if>
    </where>
 </select>