ibatis遍歷數組:ParameterObject or property was not a Collection, Array or Iterator.


這個問題在使用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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM