1. 程式人生 > >mabatis實現動態更新欄位

mabatis實現動態更新欄位

利用if標籤實現

<update id="updateUser" parameterType="xxx.pojo.user">
    update cmtinfo
     <trim prefix="set" suffixOverrides=",">
            <if test="name!=null">name=#{name},</if>
            <if test="sex!=null">sex=#{sex},</if>
            <if test="nation!=null">nation=#{nation},</if>
            <if test="birth!=null">birth=#{birth},</if>
        </trim>
    </update>