coding++:mybatis update foreach (SQL循环)批量更新

今天要做批量更新的业务,采用 mybaits 的 foreach 动态语句,遇到一些问题做下记录。

参考示例(1):

<update id=""  parameterType="">
    update tb_thread set isDelete=0
    where threadId in ( 
    <foreach collection="list" item="item" index="index" open="" close="" separator=",">
            #{item.threadId}
    </foreach>
            )     
  </update>

参考示例(2):

<update id=""  parameterType="">
    <foreach collection="list" item="item" index="index">
    update tb_question_template_seleteitem_detail set selectedName=#{item.selectedName}
    where 1=1 and  selectedId =#{item.selectedId  };
    </foreach>
</update>

这种情况一半会报错,解决方式:在数据库配置上添加 &allowMultiQueries=true

例如:jdbc:mysql://192.168.1.109:3306/healthmanage?characterEncoding=utf-8&allowMultiQueries=true

 

posted @   coding++  阅读(974)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示