where 和 if where标签相当于 where 关键字 可以自动去除第一个 and 代码实现: <select id="findDo" parameterType="lu.pojo.TbUser" resultType="lu.pojo.TbUser"> select * from pe <where> <if test="null != id"> and id=#{ id} </if> <if test=