sql中判断in
常用到<foreach></foreach>
,可以比较方便的进行拼接。 注意需要考虑集合元素的个数,以免出现sql的异常问题。
举例如下:
<select id="clearItemNotBelongTo">
DELETE
FROM
datav_screen_item_template AS tep
WHERE
tep.belong_id =
<if test="idSet !=null and idSet.size !=0">
AND tep.ID NOT IN
<foreach collection="idSet" item="id" index="index"
open="(" close=")" separator=",">
</foreach>
</if>
</select>
参考: https://blog.csdn.net/u011781521/article/details/79669180