[英]How to get a specific Object from HashMap in MyBatis foreach?
如何在MyBatis foreach循环中获取特定对象? 我写了以下代码:
<select id="getResult" resultMap="myResultMap" parameterType="java.util.HashMap">
SELECT a.myselectfield_1, a.myselectfield_2
FROM ${mySchema}.test_a a
WHERE a.field_x = 007
AND a.test_b IN
<foreach item="item" index="index" collection="#{map.get('myItems')}" open="(" separator="," close=")">
#{item}
</foreach>
ORDER BY a.myselectfield_1
</select>
这是Java HashMap,与SQL语句相关:
HashMap<String, Object> myMap = new HashMap<String, Object>();
myMap.put("mySchema", mySchema);
myMap.put("myItems", myArrayList);
我收到以下错误消息:
Error querying database. Cause: java.lang.NullPointerException: target is null for method get
如何从MyBatis foreach中的Java HashMap中读取特定值? 我正在使用1.1.1版
您不需要使用get方法来访问map元素,只需在foreach标记中编写collection =“ myItems”或collection =“ map.myItems”即可,具体取决于您定义映射器接口的方式(后者假设您使用了@Param(“ map”)注释)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.