我们首先看一段MyBatis中使用foreach循环的sql:
SELECT * FROM table where id in
<foreach item="item" collection="ids1" open="(" close=")" index="0" separator=",">
#{item}
</foreach>
这段sql执行会添加几个占位符,正确写法foreach写到一行:
正确写法为:
SELECT * FROM table where id in
<foreach item="item" collection="ids1" open="(" close=")" index="0" separator=",">#{item}</foreach>