list 批量新增或者批量修改

新增
  <insert id="insert2">
     insert into hotel_room_price (product_id, sell_date, price)
    values
    <foreach collection="list" item="emp" separator=",">
      (#{emp.productId,jdbcType=BIGINT},#{emp.sellDate,jdbcType=DATE},#{emp.price,jdbcType=DECIMAL})
    </foreach>
  </insert>
修改
  <update id="update2" parameterType="java.util.List">
        update hotel_room_price set
     price=
    <foreach collection="list" item="item" index="index" separator=" " open="case product_id" close="end">
      when #{item.productId,jdbcType=BIGINT} then #{item.price,jdbcType=DECIMAL}
    </foreach>
    where product_id in
    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
      #{item.productId,jdbcType=BIGINT}
    </foreach>
    and sell_date in
    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
      #{item.sellDate,jdbcType=DATE}
    </foreach>
  </update>
    void insert2(@Param("list") List<HotelRoomPrice> list);

    int update2(@Param("list")List<HotelRoomPrice> list);

第二种批量修改

  <!-- //房价日历-批量修改-->
  <update id="update2" parameterType="java.util.List">
    update hotel_room_price
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="price =case" suffix="end,">
        <foreach collection="list" item="i" index="index">
          <if test="i.price!=null">
            when product_id=#{i.productId} then #{i.price}
          </if>
        </foreach>
      </trim>
      <trim prefix="line_price =case" suffix="end,">
        <foreach collection="list" item="i" index="index">
          <if test="i.line_price!=null">
            when product_id=#{i.productId} then #{i.line_price}
          </if>
        </foreach>
      </trim>
      <trim prefix="line_discount =case" suffix="end,">
        <foreach collection="list" item="i" index="index">
          <if test="i.line_discount!=null">
            when product_id=#{i.productId} then #{i.line_discount}
          </if>
        </foreach>
      </trim>
      <trim prefix="calendar_discount =case" suffix="end,">
        <foreach collection="list" item="i" index="index">
          <if test="i.calendar_discount!=null">
            when product_id=#{i.productId} then #{i.calendar_discount}
          </if>
        </foreach>
      </trim>
    </trim>
    where product_id in
    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
      #{item.productId,jdbcType=BIGINT}
    </foreach>
    and sell_date in
    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
      #{item.sellDate,jdbcType=DATE}
    </foreach>
  </update>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值