ibatis 批量更新

来源:互联网 发布:300英雄血盟桐人淘宝 编辑:程序博客网 时间:2024/06/05 11:41

一条条更新效率太低,以下方式将提高效率。当然还有replace into的方式,但是该方式需要所有的字段,否则就为null。并且是根据主键或者是唯一索引来更新,有时候并不方便。

更新的sql:

    update tblsupertitleresult set result =case             when (userHhCode=2001 and titleId=1)then  90             when (userHhCode=2001 and titleId=2)then  70             end             ,checkState = case              when (userHhCode=2001 and titleId=1)then  80             when (userHhCode=2001 andtitleId=2)then  120             end             where (userHhCode=2001 and titleId=1) or(userHhCode=2001 and titleId=2)  

xml配置:

<update id="batchUpdateKeywords">
        update sem_keywords
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="platPlanId = case" suffix="end,">
                <foreach collection="list" item="it" index="index">
                        when platKeywordsId=#{it.platKeywordsId}  then #{it.platPlanId}
                </foreach>
            </trim>
             </trim>
        where
        <foreach collection="list" separator="or" item="it" index="index">
            (id= #{it.id} )
        </foreach>
    </update>

0 0