mybatis 遍历map;

时间:2023-03-09 03:17:29
mybatis 遍历map;

mybatis 遍历map;

参考http://blog.****.net/hj7jay/article/details/78652050

ps:

${m[key]}
这是显示 打印的key读value写法
注意:根据key获取到map的方式,如下:
#{content[${key}]} 或者 ${content[key]}方式,两个方式的#和$不能随便换位置。
如:
<!--查同步表-->
<insert id="insertSynData" parameterType="java.util.Map" >
insert into ${tb_target}(${columns})
<foreach collection="list" item="m" open="" close="" separator=" union all ">
select
<foreach collection="m.keys" item="key" open="" close="" separator=",">
<choose>
<when test="key=='案例主题'">
#{m[${key}],jdbcType=CLOB}
</when>
<otherwise>
${m[key]}
</otherwise>
</choose>
</foreach>
from dual
</foreach>
</insert>