MyBatis使用foreach语句报错The expression 'array' evaluated to a null val

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zwl18210851801/article/details/82665595

原因:传递一个 List 实例或者数组作为参数对象传给 MyBatis时,MyBatis 会自动将它包装在一个 Map 中,用名称作为键。

情况一:直接传参Long[]数组

List<SysUserEntity> listByUser(Long[] ids);
MyBatis文件中:collection="array"
o.org_id IN
<foreach item="ids" collection="array" open="(" separator="," close=")">
   #{ids}
</foreach>

情况二:使用Query传递数组参数

params.put("ids",ids);

Query query = new Query(params);

MyBatis文件中:collection="ids"

o.org_id IN
<foreach item="ids" collection="ids" open="(" separator="," close=")">
	#{ids}
</foreach>

猜你喜欢

转载自blog.csdn.net/zwl18210851801/article/details/82665595
val