这个问题在使用ibatis的<iterate></iterate>时出现的,很简单,但是蛋疼了很久,记下来
首先从错误提示看,明显意思是你给出ibatis的参数不对路,人家不认识,我也是被这个提示误导了
1.先来个小学的
//传入的参数只有数组/集合/迭代器的时候 public List findall(SqlMapClient sqlMap, String[] ids) throws SQLException{ return sqlMap.queryForList("findall",ids) }
<!--传入值唯一数组,所以甚至这么干就行-->
<statement id="findall" resultClass="..User"> select * from user_table where id in <iterate open="(" close=")" conjunction=","> #[]# </iterate> </statement>
<!--r如果是list需要加个参数类型,然后指定下-->
<statement id="findall" resultClass="..User" parameterClass="java.util.List">
select * from user_table where id in
<iterate open="(" close=")" conjunction=",">
#ids[]#
</iterate>
</statement>
2.来个中学的(倒在这里了)
//传入对象,那么User中有个属性叫爱好 hobbies[] 同时form传递来的字段叫hobby public List findAll(SqlMapClient sqlMap,User user){ return sqlMap.queryForList("findall",user); }
//
<statement id="findall" parameterClass=="...User" resultClass="...User">
select * from table_user where 1=1 <isNotEmpty property="org_ids" prepend="and">
hobby in <iterate property="hobbies" open="(" close=")" conjunction=","> #hobbies[]# </iterate> </isNotEmpty>
</statement>
3.还没用过大学的map遍历 对象遍历 就不说了
慢慢看这个
http://hongzhguan.iteye.com/blog/1222353