mybatis 批量更新

原创
2017/08/31 17:10
阅读数 128
mybatis支持foreach语句,
语法大致如下:
    <update id="batchUpdate">
            update tblsupertitleresult
            <trim prefix="set" suffixOverrides=",">
            <trim prefix="checkState =case" suffix="end,">
                <foreach collection="list" item="i"  index="index">
                        <if test="i.checkState!=null">
                         when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.checkState}
                        </if>
                </foreach>
             </trim>
             <trim prefix=" correctDate =case"  suffix="end,">
                <foreach collection="list" item="i"  index="index">
                        <if test="i.correctDate!=null">
                         when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.correctDate}
                        </if>
                </foreach>
             </trim>
             <trim prefix="result =case"  suffix="end,"  >
                <foreach collection="list"item="i" index="index">
                        <if test="i.result!=null">
                         when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.result}
                        </if>
                </foreach>
             </trim>
             </trim>
            where
            <foreach collection="list" separator="or"item="i" index="index" >
             (userHhCode =#{i.userHhCode} andtitleId=#{i.titleId})
         </foreach>
</update>
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部