<!-- 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>
**mybatis处理SQL查询中的where后面and常用的2种方法**
最新推荐文章于 2024-07-20 16:09:10 发布
本文探讨了MyBatis框架中动态SQL的两种实现方式,包括如何使用if标签和where标签来构建条件查询语句,确保SQL语句的正确性和效率。
626

被折叠的 条评论
为什么被折叠?



