mybatis代码
--------------------------------------------
<if test="search.dataforArray != null">
and datefor in
<foreach item="search.dataforArray" index="index" collection="search.dataforArray" open="(" separator="," close=")">#{search.dataforArray}</foreach>
</if>
---------------------------------------------
如果数组为空时出现错误
nested exception is org.apache.ibatis.builder.BuilderException: The expression 'search.dataforArray' evaluated to a null value.
请问如何修改呢?
答案:
<if test="search.dataforArray != null">
and datefor in ;
<foreach item="item" index="index";
collection="search.dataforArray";
open="("separator="," close=")">#{item}</foreach>
</if>。
循环体中的具体对象:支持属性的点路径访问,如item.age,item.info.details,具体说明:在list和数组中是其中的对象,在map中是value,collection,要做foreach的对象,作为入参时,List<?>对象默认用list代替作为键,数组对象有array代替作为键,Map对象没有默认的键。当然在作为入参时可以使用@Param("keyName")来设置键,设置keyName后,list,array将会失效。
除了入参这种情况外,还有一种作为参数对象的某个字段的时候。
<if test="search.dataforArray != null">
and datefor in
<foreach item="item" index="index" collection="search.dataforArray" open="(" separator="," close=")">#{item}</foreach>
</if>本回答被提问者和网友采纳
改为:
<if test="search.dataforArray != null and search.dataforArray !=''" >