用Map的格式更新

<update id="updateByMap">
    update sys_user set
        <foreach collection="_parameter" item="val" index="key"  separator=",">
            ${key}=#{val}
        </foreach>
    where id=#{id}
</update>

这样就不用挨个set了

    <update id="updateByIdSelective">
        update sys_user set
        <set>
            <if test="userName!=null and userName!=''">
                user_name=#{userName},
            </if>
            <if test="userPassword!=null and userPassword!=''">
                user_password=#{userPassword},
            </if>
            <if test="userEmail!=null and userEmail!=''">
                userEmai=#{userEmail},
            </if>
            <if test="userInfo!=null and userInfo!=''">
                user_info=#{userInfo}
            </if>
            <if test="heardImg!=null">
                head_img=#{headImg,jdbcType=BLOB},
            </if>
            <if test="createTime!=null">
                create_time =#{createTime,jdbcType=TIMESTAMP},
            </if>
            id=#{id},
        </set>
        where id=#{id}
    </update>

 

posted @ 2018-10-09 10:20  Montauk  阅读(301)  评论(0编辑  收藏  举报