我是靠谱客的博主 勤恳面包,这篇文章主要介绍Mybatis中利用foreach批量更新数据,现在分享给大家,希望可以做个参考。

1.xml中书写的方式

<update id="batchUpdate" parameterType="list">
         update songs
            <trim prefix="set" suffixOverrides=",">
                 <trim prefix="path =case" suffix="end,">
                     <foreach collection="list" item="i" index="index">
                             <if test="i.songid!=null">
                                  when songid=#{i.songid} then #{i.path}
                             </if>
                     </foreach>
                  </trim>
             </trim>
            where songid in 
            <foreach collection="list"  item="i" index="index" open="(" separator="," close=")">
              #{i.songid}
          </foreach>
    </update>

2.Mapper中方法

void batchUpdate(List<Songs> recordList);

3.打印出来的sql格式

UPDATE songs 
SET path =
CASE  SONGID 
      WHEN '10800537' THEN    'C:/songs/10800537.mpg'
      WHEN '10800118' THEN    'C:/songs/10800118.mpg'
END    
WHERE   SONGID IN ('10800537','10800118')

最后

以上就是勤恳面包最近收集整理的关于Mybatis中利用foreach批量更新数据的全部内容,更多相关Mybatis中利用foreach批量更新数据内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(150)

评论列表共有 0 条评论

立即
投稿
返回
顶部