2015-10-06 59 views
3
SELECT * 
FROM mytable 
<foreach item="item" index="index" collection="myhashmap.entrySet()" open=" WHERE (" separator=" OR ("> table.attribute= #{item.key} 
    <foreach item="item2" index="index" collection="#{item.value}" separator=" ," open=" AND table.attribute IN (" close="))"> 
     #{item2.value} 
     </foreach> 
</foreach>  

對散列表的迭代有效,但列表(它在item.value中)不起作用。MyBatis - 遍歷整個列表,它是嵌套的foreach循環中的HashMap的值

Map<Integer, List<Integer>> myhashmap = new HashMap<Integer, List<Integer>>(); 

{item.value.iterator()}不起作用。

Exception: 
    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression '#{item.value}'. Return value ({[5800]=null}) was not iterable. 

其中5800是List

任何幫助表示讚賞的整數值!

+0

你試過item.getValue()未經#{} – vvs

+0

沒有,沒有工作。 – 98percentmonkey

回答

1
<foreach item="element" index="index" collection="mySet.entrySet()" open=" WHERE ((" separator=" OR ("> table.attribute1= #{element.key} 
    <foreach item="item" index="index" collection="element.value" separator=" ," open=" AND table.attribute2 IN (" close="))"> 
     #{item} 
     </foreach> 
</foreach> 

這爲我修好了!