【转】MyBatis 通过Map更新
原文:mybatis使用map批量更新(Oracle)
有个需求,MyBatis 通过Map的key作为条件,value作为更新后的值来更新数据。
<update id="batchUpdateLogistics" parameterType="map"> <foreach collection="callMap.entrySet()" item="value" index="key" open="begin" close=";end;" separator=";"> update TD_LOGISTICS t set t.record=#{value} where t.sessionId=#{key} </foreach> </update> <update id="batchUpdateLogistics" parameterType="map"> <foreach collection="callMap.entrySet()" item="value" index="key" open="begin" close="end;" separator=""> update TD_LOGISTICS t set t.record=#{value} where t.sessionId=#{key}; </foreach> </update> <update id="batchUpdateLogistics" parameterType="map"> begin <foreach collection="callMap.entrySet()" item="value" index="key" separator=""> update TD_LOGISTICS t set t.record=#{value} where t.sessionId=#{key}; </foreach> end; </update>