sql查询时在遍历集合(是ArrayList对象)时报错:
解决mybatis foreach 错误: Parameter ‘__frch_item_0‘ not found
Caused by: org.apache.ibatis.binding.BindingException: Parameter '__frch_item_0' not found. Available parameters are [param1, bean, param2, param3, pOrderBy, org]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:165) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:44) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:186) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.executor.CachingExecutor.createCacheKey(CachingExecutor.java:129) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:76) ~[mybatis-3.2.7.jar:3.2.7]
at sun.reflect.GeneratedMethodAccessor86.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45005) ~[na:1.7.0_67]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_67]
报错写法:
<if test="bean.modelIds != null and bean.modelIds != '' and bean.modelIds.size() > 0">
<foreach collection="bean.modelIds" index="index" item="item" open="and (" separator="or" close=")">
#{item}
</foreach>
</if>
改后的写法
<if test="bean.modelIds != null and bean.modelIds != '' and bean.modelIds.size() > 0">
<foreach collection="bean.modelIds" index="index" item="item" open="and (" separator="or" close=")">
#{bean.modelIds[${index}],jdbcType=VARCHAR}
</foreach>
</if>