mybatis--where标签
SELECT * FROM book
<where>
<if test="name != null">
and name = #{name}
</if>
<if test="title != null">
and title like #{title}
</if>
</where>
where标签知道只有当一个及以上的if标签成立时,才会在sql语句中拼接上where。同时也会自动去除出现的第一个and。
没有if成立时
select * from book
有if成立时(第一个and会去除)
select * from book
where name=#{name} and title like #{title}
浙公网安备 33010602011771号