Dao层如下:
int dynamicUpdateTable(@Param("table") Map table);
xml Sql:
<update id="dynamicUpdateTable" parameterType="map">
UPDATE ${table.tabName} SET
<foreach item="value" index="key" collection="table.entrySet()" separator=",">
<if test="key!='tabName' and key!='id'">
${key} = #{value}
</if>
</foreach>
WHERE id=#{tab.id}
</update>
入参:
{
"colname":"40",
"id":1,
"createTime":"2018-02-08",
"userName":"marvers",
"tabName":"tab_m"
}