1、foreach 中集合size如果为0 则不添不会添加open和 close
2、foreach 中如果集合为null 默认情况抛出异常异常,
3、可以在foreach种添加nullable为true,让集为null的时候不抛异常
<foreach nullable="true" item="item" index="index" collection="deptIds" open=" and t.dept_id in (" separator=" , " close=" ) ">
#{item}
</foreach>
4、可以在配置文件中添加nullableOnForEach,来设置foreach上的nullable的默认值
<setting name="nullableOnForEach" value="true" />
5、nullableOnForEach属性和nullable均在3.5.9及以上版本
本文详细介绍了MyBatis中foreach元素的nullable属性使用方法,包括如何避免集合为null时抛出异常,如何在配置文件中设置默认值,以及这些特性支持的版本。
3626

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



