[英]How to get a specific Object from HashMap in MyBatis foreach?
How can I get a specific object in a MyBatis foreach loop? 如何在MyBatis foreach循环中获取特定对象? I have written the following code: 我写了以下代码:
<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>
This is the Java HashMap, which is relevant for the SQL Statement: 这是Java HashMap,与SQL语句相关:
HashMap<String, Object> myMap = new HashMap<String, Object>();
myMap.put("mySchema", mySchema);
myMap.put("myItems", myArrayList);
I get the following error message: 我收到以下错误消息:
Error querying database. Cause: java.lang.NullPointerException: target is null for method get
How can I read a specific value from a Java HashMap in MyBatis foreach? 如何从MyBatis foreach中的Java HashMap中读取特定值? I´m using Version 1.1.1 我正在使用1.1.1版
您不需要使用get方法来访问map元素,只需在foreach标记中编写collection =“ myItems”或collection =“ map.myItems”即可,具体取决于您定义映射器接口的方式(后者假设您使用了@Param(“ map”)注释)。
you should be use $ replace # in foreach. 您应该在foreach中使用$ replace#。
more information can see: 更多信息可以看到:
Mybatis foreach collection is a list in a map-parameter Mybatis foreach集合是地图参数中的列表
MyBatis Issue with IN Condition <foreach with List inside a Map MyBatis问题与IN条件<foreach与地图内的列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.