mybatis traverse the map

mytabis is a searchable map, and tried many other methods will not eventually use the following methods are possible:

1.mapper.java as follows (note @Param to add annotations, or not, I'll be there to toss a lot of time):

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

2.mapper.xml follows (note collection = "map.entrySet ()" or collection = "map" will do):

    <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>

  

Guess you like

Origin www.cnblogs.com/ismallboy/p/11076333.html