Mybatis中update时set和if的用法

Mybatis 中把更新的语句写在标签中,每个if都添加,组合sql的时候回自动去掉,符号


    <update id="updateSetting">
        update gk_cmpt_func
        <set>
            <if test="setting.mobile != null">
                switch_mobile = #{setting.mobile},
            </if>
            <if test="setting.countDown != null">
                switch_countdown=#{setting.countDown},
            </if>
            <if test="setting.news != null">
                switch_news=#{setting.news},
            </if>
            <if test="setting.banner != null">
                switch_banner=#{setting.banner},
            </if>
            <if test="setting.newsAlias != null">
                news_alias=#{setting.newsAlias},
            </if>
            <if test="setting.mileage != null">
                switch_mileage=#{setting.mileage},
            </if>
            <if test="setting.switchScoreReview != null">
                switch_scoreReview=#{setting.switchScoreReview},
            </if>
        </set>
        where cmpt_id = #{setting.cmptId}
    </update>

你可能感兴趣的:(mybatis)