[英]MyBatis - Iterate over list which is value of HashMap in nested foreach loops
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>
The Iteration over the hashmap works, but the list (which is in item.value) doesn't work. 对hashmap的迭代有效,但列表(在item.value中)不起作用。
Map<Integer, List<Integer>> myhashmap = new HashMap<Integer, List<Integer>>();
{item.value.iterator()} doesn't work too. {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.
Where 5800 is a Integer-Value of the List 其中5800是列表的整数值
Any help is appreciated! 任何帮助表示赞赏!
<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>
This fixed it for me! 这为我修好了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.