【发布时间】:2019-12-16 08:38:25
【问题描述】:
我在 myBatis 中有以下映射。
<update id="updatePersons" parameterType="Map">
begin
<foreach item="fname" collection="fnames" index="index" separator=";">
update person set age = #{ages}[#{index}] where fname = #{fname}
</foreach>;
end;
</update>
它应该更新所有名字与作为参数传递的名字匹配的人的年龄。
以及Java中对应的调用:
Map<String, List<String>> map = new HashMap<>();
List<String> fnames = new ArrayList<>();
List<Integer> ages = new ArrayList<>();
map.put("fnames", fnames);
map.put("ages", ages);
session.update("person.updatePersons", map);
集合fnames 和ages 的大小相同。我在 myBatis-mapping 中通过索引访问 ages 的元素有些困难。我已经尝试过括号,如第一个 sn-p 中所示。我也尝试了#{ages}.get(#index),但没有任何效果。有可能吗?
【问题讨论】:
标签: mybatis