Mybatis loop modification, when multiple fields, where's in multiple fields

mybatis–foreach loop update modification
When judging, double primary key or multiple judgments need to judge when multiple fields and where in multiple fields

    <update id="updateAppSetDatas" parameterType="list">
        update app_set_data
        <set>
            <trim prefix="appName=case" suffix="end,">
                <foreach collection="appSetDatas" item="item" index="index">
                    <if test="item.app_name != null and item.app_name != ''">
                        when area_id=#{
    
    item.areaId} and app_id =#{
    
    item.appId} then #{
    
    item.app_name}
                    </if>
                    <if test="item.app_name == null and item.app_name == ''">
                        when area_id=#{
    
    item.areaId} and app_id =#{
    
    item.appId} then app_set_data.appName
                    </if>
                </foreach>
            </trim>
            <trim prefix="pass_reader1=case" suffix="end,">
                <foreach collection="appSetDatas" item="item" index="index">
                    <if test="item.passReader1 != null">
                        when area_id=#{
    
    item.areaId} and app_id =#{
    
    item.appId} then #{
    
    item.passReader1}
                    </if>
                    <if test="item.passReader1 == null">
                        when area_id=#{
    
    item.areaId} and app_id =#{
    
    item.appId} then app_set_data.pass_reader1
                    </if>
                </foreach>
            </trim>
            <trim prefix="update_time=case" suffix="end,">
                <foreach collection="appSetDatas" item="item" index="index">
                    <if test="item.updateTime != null">
                        when area_id=#{
    
    item.areaId} and app_id =#{
    
    item.appId} then #{
    
    item.updateTime}
                    </if>
                    <if test="item.updateTime == null">
                        when area_id=#{
    
    item.areaId} and app_id =#{
    
    item.appId} then app_set_data.update_time
                    </if>
                </foreach>
            </trim>
        </set>
        where (area_id,app_id) in
        <foreach collection="appSetDatas" item="item" index="index" separator="," open="(" close=")">
            (#{
    
    item.areaId},#{
    
    item.appId})
        </foreach>
    </update>

Supongo que te gusta

Origin blog.csdn.net/weixin_45265547/article/details/127220225
Recomendado
Clasificación