数据库的批量操作

 <update id="updateBatch" parameterType="java.util.List">
        update am_dept
        set `status` = case dept_id
        <foreach collection="list" item="item">
            when #{item.deptId,jdbcType=BIGINT} then #{item.status,jdbcType=TINYINT}
        </foreach>
        end
        where dept_id in
        <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item.deptId,jdbcType=BIGINT}
        </foreach>
    </update>
    dept_id是主键
    

 <update id="batchUpdate" parameterType="java.util.List">
        update im_safe_stock
        set
        material_inventory_id --(列名字)= case safe_stock_id  ---主键
        <foreach collection="list" item="po">
            when #{po.safeStockId,jdbcType=BIGINT} then #{po.materialInventoryId,jdbcType=BIGINT}
        </foreach>
        end,
        lower_limit --(列名字)= case safe_stock_id  ---主键
        <foreach collection="list" item="po">
            when #{po.safeStockId,jdbcType=BIGINT} then #{po.lowerLimit,jdbcType=DECIMAL}
        </foreach>
        end,
        way --(列名字)= case safe_stock_id  ---主键
        <foreach collection="list" item="po">
            when #{po.safeStockId,jdbcType=BIGINT} then #{po.way,jdbcType=TINYINT}
        </foreach>
        end
        where safe_stock_id in  ---主键
        <foreach collection="list" item="po" open="(" separator="," close=")">
            #{po.safeStockId,jdbcType=BIGINT}
        </foreach>
    </update>

查询自创

UNION ALL 不允许重复
UNION 消去重复
forreach 后面一定是 ","而不是 ";"
<foreach collection="list" item="dayTime" separator="union all">
    (select #{dayTime} as dayTime, IFNULL(sum(stroage_num),0.0) as num
    from kb_product_rank
    where dates like #{dayTime} '%')
</foreach>

      <!--  根据userId和权限id批量更新用户权限中间表-->
      Integer insertBatch(@Param("uids") List<Long> uids,@Param("perms") List<Long> perms);
  <insert id="insertBatch">
    insert into am_m_user_authority(user_id,authority_id)values
    <foreach collection="uids" item="uid" separator=",">
       <foreach collection="perms" item="perm" separator=",">
         (
           #{uid,jdbcType=BIGINT},
           #{perm,jdbcType=BIGINT}
         )
       </foreach>
    </foreach>
  </insert>
  --双重list
   
    <choose>
    <when
test="parentId != null and parentId !=0">
        where au.parent_id = #{parentId,jdbcType=BIGINT} and r.role_id = #{roleId,jdbcType=BIGINT} and au.type =
        #{type,jdbcType=TINYINT}
    </when>
    <otherwise>
        where au.parent_id = 0 and au.type = #{type,jdbcType=TINYINT} and r.role_id = #{roleId,jdbcType=BIGINT}
    </otherwise>
</choose>
--相当于if  条件
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值