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

参考示例(1):

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

 

相关文章:

  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2021-08-17
  • 2021-08-01
  • 2021-06-04
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
相关资源
相似解决方案