美文网首页
MyBatis使用Map

MyBatis使用Map

作者: 我想放假休息 | 来源:发表于2021-11-24 18:45 被阅读0次

mytabis是可以遍历map的,试过很多其他的方法都不行,最终使用如下方法是可以的:

1.mapper.java如下(注意要加@Param注解,否则不行,我就在这里折腾了不少时间):

int updateBatch(@Param("map") Map<Long, String> map);

2.mapper.xml如下(注意collection="map.entrySet()"或者collection="map"都行):

<update id="updateBatch" parameterType="java.util.Map">
    update tv_column
    set name = case pk
    <foreach collection="map.entrySet()" index="key" item="value">
        when #{key} then #{value}
    </foreach>
    end
    where pk in
    <foreach collection="map.entrySet()" index="key" separator="," open="(" close=")">
        #{key}
    </foreach>
</update>

相关文章

网友评论

      本文标题:MyBatis使用Map

      本文链接:https://www.haomeiwen.com/subject/gzfotrtx.html