<!-- 1:后面跟1=1 决对成立-->
<select id="queryPersonByidAndNo">
select * from person where 1=1
<if test=" id !=null and id !='' ">
and id = #{id}
</if>
<if test=" id !=null and id !='' ">
and no = #{no}
</if>
</select>
<!-- 2 :后面跟where标签,会将第一个and过滤(不会过滤第二个)-->
<select id="queryPersonByidAndNo">
select * from person where
<where>
<if test=" id !=null and id !='' ">
and id = #{id}
</if>
<if test=" id !=null and id !='' ">
and no = #{no}
</if>
</where>
</select>
————————————————
版权声明:本文为优快云博主「java小小小小牛」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/qq_37296212/article/details/83178450