mysql批量新增和修改示例(foreach 使用)

批量新增:

in的map中的list查询

<!-- 获取商品分类 -->
<select id="getGoodClass" parameterType="list" resultMap="shopGoodClassRVO">
SELECT T.GC_ID,
       T.GC_NAME,
       T.TYPE_ID,
       T.TYPE_NAME,
       T.STORE_ID,
       T.GC_PARENT_ID,
       T.GC_SORT,
       T.GC_SHOW,
       T.GC_KEYWORD,
       T.CREATORID,
       T.CREATETIME,
       T.UPDATEID,
       T.UPDATETIME,
       T.DELFLAG
  FROM T_SHOP_GOODS_CLASS T
  WHERE T.DELFLAG = '0'
<if test="type == 1" >
AND t.gc_parent_id is null
</if>
<if test ="gc_parent_id != null">
    AND T.GC_PARENT_ID IN 
    <foreach collection ="gc_parent_id" item="item" index= "index" open="(" separator="," close=")">
            #{item.gcId}
        </foreach >
</if>
  ORDER BY T.GC_SORT,T.GC_ID
</select>

<!-- 批量新增接收对象 -->
  <insert id="addRecive" parameterType="java.util.List">
insert into t_news_important_sendee
            (NI_ID, 
        DEPART_ID,
        U_ID,
            CREATORID,
            CITY_NAME)
            values
        <foreach collection ="list" item="item" index= "index" separator =",">
            (
            #{item.niId},
            #{item.departId},
            #{item.uId},
            #{item.creatorid},
            #{item.cityName})
        </foreach >
  </insert>

批量修改/删除

批量修改是jdbc的配置必须加个&allowMultiQueries=true;

如:jdbc:mysql://192.168.1.85:3307/gz_test?useSSL=false&allowMultiQueries=true

 <!-- 批量修改员工车牌号-->
  <update id="updateCar" parameterType="java.util.List">
  <foreach collection="list" item="item" index="index" open="" close="" separator=";">
  update t_user_department t 
  set t.UDT_LICENSE_PLATE = #{item.udt_license_plate},
      t.UPDATEID = #{item.updateId} 
      where t.UDT_SAPID = #{item.udt_sapid} 
      </foreach> 
  </update>

  <!-- 批量删除员工-->
  <update id="delStaffs" parameterType="java.util.List">
  <foreach collection="list" item="item" index="index" open="" close="" separator=";">
  update t_user t set t.DELFLAG = '1',t.UPDATEID = #{item.updateid} where t.U_ID = #{item.uId} 
      </foreach> 
  </update>

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值