mybatis 批量更新

<!--批量更新机型数据-->
    <update id="batchUpdateBsVendingModelBoxs" parameterType="java.util.List">
          update bs_vending_model_box v
          <trim prefix="SET" suffixOverrides=",">
              <trim prefix="deviceId=case" suffix="end,">
                  <foreach collection="bsVendingModelBoxVoList" item="item" index="index">
                      <if test="item.deviceId!=null">
                          when logid=#{item.logid} then #{item.deviceId}
                      </if>
                  </foreach>
              </trim>
              <trim prefix="factoryId=case" suffix="end,">
                  <foreach collection="bsVendingModelBoxVoList" item="item" index="index">
                      <if test="item.factoryId!=null">
                          when logid=#{item.logid} then #{item.factoryId}
                      </if>
                  </foreach>
              </trim>
              <trim prefix="deviceCode=case" suffix="end,">
                  <foreach collection="bsVendingModelBoxVoList" item="item" index="index">
                      <if test="item.deviceCode!=null">
                          when logid=#{item.logid} then #{item.deviceCode}
                      </if>
                  </foreach>
              </trim>
              <trim prefix="cabinetType=case" suffix="end,">
                  <foreach collection="bsVendingModelBoxVoList" item="item" index="index">
                      <if test="item.cabinetType!=null">
                          when logid=#{item.logid} then #{item.cabinetType}
                      </if>
                  </foreach>
              </trim>
              <trim prefix="boxCode=case" suffix="end,">
                  <foreach collection="bsVendingModelBoxVoList" item="item" index="index">
                      <if test="item.boxCode!=null">
                          when logid=#{item.logid} then #{item.boxCode}
                      </if>
                  </foreach>
              </trim>
              <trim prefix="boxType=case" suffix="end,">
                  <foreach collection="bsVendingModelBoxVoList" item="item" index="index">
                      <if test="item.boxType!=null">
                          when logid=#{item.logid} then #{item.boxType}
                      </if>
                  </foreach>
              </trim>
              <trim prefix="bCol=case" suffix="end,">
                  <foreach collection="bsVendingModelBoxVoList" item="item" index="index">
                      <if test="item.bCol!=null">
                          when logid=#{item.logid} then #{item.bCol}
                      </if>
                  </foreach>
              </trim>
              <trim prefix="bRow=case" suffix="end,">
                  <foreach collection="bsVendingModelBoxVoList" item="item" index="index">
                      <if test="item.bRow!=null">
                          when logid=#{item.logid} then #{item.bRow}
                      </if>
                  </foreach>
              </trim>
              <trim prefix="createTime=case" suffix="end,">
                  <foreach collection="bsVendingModelBoxVoList" item="item" index="index">
                      <if test="item.createTime!=null">
                          when logid=#{item.logid} then #{item.createTime}
                      </if>
                  </foreach>
              </trim>
              <trim prefix="corpId=case" suffix="end,">
                  <foreach collection="bsVendingModelBoxVoList" item="item" index="index">
                      <if test="item.corpId!=null">
                          when logid=#{item.logid} then #{item.corpId}
                      </if>
                  </foreach>
              </trim>
          </trim>
        where
        <foreach collection="bsVendingModelBoxVoList" separator="or" item="item" index="index">
            logid=#{item.logid}
        </foreach>
    </update>

批量更新另一种形式

<!--批量修改站点箱子-->
    <update id="batchUpdateVendingLane" parameterType="java.util.Map">
        update bs_vending_lane
		<trim prefix="SET" suffixOverrides=",">
        <trim prefix="logid =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.logid!=null">
                    when logid=#{item.logid} then #{item.logid}
                </if>
            </foreach>
        </trim>
        <trim prefix="slaneId =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.slaneId!=null">
                    when logid=#{item.logid} then #{item.slaneId}
                </if>
            </foreach>
        </trim>
        <trim prefix="siteId =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.siteId!=null">
                    when logid=#{item.logid} then #{item.siteId}
                </if>
            </foreach>
        </trim>
        <trim prefix="factoryId =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.factoryId!=null">
                    when logid=#{item.logid} then #{item.factoryId}
                </if>
            </foreach>
        </trim>
        <trim prefix="deviceCode =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.deviceCode!=null">
                    when logid=#{item.logid} then #{item.deviceCode}
                </if>
            </foreach>
        </trim>
        <trim prefix="cabinetType =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.cabinetType!=null">
                    when logid=#{item.logid} then #{item.cabinetType}
                </if>
            </foreach>
        </trim>
        <trim prefix="seqId =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.seqId!=null">
                    when logid=#{item.logid} then #{item.seqId}
                </if>
            </foreach>
        </trim>
        <trim prefix="boxId =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.boxId!=null">
                    when logid=#{item.logid} then #{item.boxId}
                </if>
            </foreach>
        </trim>
        <trim prefix="boxCode =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.boxCode!=null">
                    when logid=#{item.logid} then #{item.boxCode}
                </if>
            </foreach>
        </trim>
        <trim prefix="boxType =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.boxType!=null">
                    when logid=#{item.logid} then #{item.boxType}
                </if>
            </foreach>
        </trim>
        <trim prefix="bCol =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.bCol!=null">
                    when logid=#{item.logid} then #{item.bCol}
                </if>
            </foreach>
        </trim>
        <trim prefix="bRow =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.bRow!=null">
                    when logid=#{item.logid} then #{item.bRow}
                </if>
            </foreach>
        </trim>
        <trim prefix="curState =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.curState!=null">
                    when logid=#{item.logid} then #{item.curState}
                </if>
            </foreach>
        </trim>
        <trim prefix="stateTime =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.stateTime!=null">
                    when logid=#{item.logid} then #{item.stateTime}
                </if>
            </foreach>
        </trim>
        <trim prefix="useType =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.useType!=null">
                    when logid=#{item.logid} then #{item.useType}
                </if>
            </foreach>
        </trim>
        <trim prefix="orderId =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.orderId!=null">
                    when logid=#{item.logid} then #{item.orderId}
                </if>
            </foreach>
        </trim>
        <trim prefix="userId =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.userId!=null">
                    when logid=#{item.logid} then #{item.userId}
                </if>
            </foreach>
        </trim>
        <trim prefix="createTime =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.createTime!=null">
                    when logid=#{item.logid} then #{item.createTime}
                </if>
            </foreach>
        </trim>
        <trim prefix="corpId =case" suffix="end,">
            <foreach collection="vendingLaneList" item="item" index="index">
                <if test="item.corpId!=null">
                    when logid=#{item.logid} then #{item.corpId}
                </if>
            </foreach>
        </trim>
		</trim>
        <where>
			<foreach collection="vendingLaneList" separator="or" item="item" index="index">
				logid=#{item.logid}
			</foreach>
		</where>
    </update>

数据层参数的传递
Map<String, Object> map = new HashMap<String, Object>();
map.put("vendingLaneList", vendingLaneList);
return super.getSqlSession().update("VendingLane.batchUpdateVendingLane", map);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值