mybatis 动态 update

    xiaoxiao2021-12-14  16

    使用mybatis写sql,需要动态更新对象数据,每次需要更新的字段不同,

    <update id="update" parameterType="com.commuli.po.User"> update s_user <trim prefix="set" suffixOverrides=","> <if test="name!=null">name=#{name},</if> <if test="age!=null">age=#{age},</if> <if test="address!=null">address=#{address},</if> </trim> where id=#{id} </update>

    注:trim标签用来去掉sql中最后一个字段的逗号“,”。

    转载请注明原文地址: https://ju.6miu.com/read-965017.html

    最新回复(0)