mybatis循环修改,when多个字段,where的in多个字段

mybatis–foreach循环update修改
判断时双主键或者多个判断 需要when多个字段 和 where的in多个字段判断

    <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>

猜你喜欢

转载自blog.csdn.net/weixin_45265547/article/details/127220225
今日推荐