zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    3.13作业 制作网页布局
    3.11 框架和样式表
    表单
    3.8学习记录
    第一次作业
    数据库增删改查
    数据库三大范式
    数据库中的时间戳
    数据库的主键与外键
    登录页面
  • 原文地址:https://www.cnblogs.com/codingmode/p/12548454.html
Copyright © 2011-2022 走看看