2015-10-06 29 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> 

这为我修好了!