Mybatis之foreach遍历Map
方式一:利用map的entrySet()方法
<insert id="XXX" parameterType="java.util.Map"> INSERT INTO table(a, b) VALUES <foreach collection="param.entrySet()" open="(" separator="," close=")" index="key" item="val"> #{key}, #{val} </foreach> </insert> </mapper>
方式二:
<insert id="XXX" parameterType="java.util.Map"> INSERT INTO table <foreach collection="params.keys" item="key" open="(" separator="," close=")"> 获取值:#{param[key]} 键:#{key} </foreach> VALUES <foreach collection="param.value" item="val" open="(" separator="," close=")"> 值:#{val} </foreach> </insert>
转载地址:https://blog.csdn.net/qq_37014990/article/details/79775906