- 1、where标签只有帮你动态去掉and和or的作用,它不能帮你动态添加!
select * from emp
<where>
<if test="name!=null">`name` like concat('%', #{name}, '%')</if>
<if test="gender!=null">and gender = #{gender}</if>
<if test="begin!=null and end!=null">and entrydate between #{begin} and #{end}</if>
</where>
这样才是对的,千万不要以为能自动给你加上and
- 2、set标签只有帮你动态去掉逗号的作用,它不能帮你动态添加!
<set>
<if test="username != null">username=#{username},</if>
<if test="password != null">password=#{password},</if>
<if test="email != null">email=#{email},</if>
<if test="bio != null">bio=#{bio}</if>
</set>
逗号你自己不能省去!!!!