<update id="batchUpdate" >
<foreach collection="userList" item="item" index="index" separator=";">
update t_user_data set `province_id`=#{item.provinceId} where member_id = #{item.memberId}
</foreach>
</update>
sql如下:
update t_user_data_1 set `province_id`=?,`region_id`=? where member_id = ? ;
update t_user_data set `province_id`=?,`region_id`=? where member_id = ? ;
<update id="batchUpdate" >
<foreach collection="userList" item="item" index="index" separator=";">
update ${item.tableName} set `province_id`=#{item.provinceId} where member_id = #{item.memberId}
</foreach>
</update>
这里需要注意一下:表名和列名需要用${}来传入,参数才用#{}。
最终sql如下:
update t_user_data_1 set `province_id`=?,`region_id`=? where member_id = ? ;
update t_user_data_2 set `province_id`=?,`region_id`=? where member_id = ? ;