Java,Mybatis 批量修改

一:批量修改

Dao层的方法名:public int editSave(@Param("list")List<MaterialStockUnpack> list,@Param("tableName")String tableName);

批量修改多个参数:这里 表名tableName 为可编号参数,如果只是一张表,则这个字段写固定的就好

<update id="editSave" parameterType="java.util.List">
       update ${tableName} 
       <trim prefix="set" suffixOverrides=",">
               <trim prefix="stock_num =case" suffix="end,">
                   <foreach collection="list" item="item" index="index">
                       <if test="item.stockNum !=null and item.stockNum != -1">
                         when relation_id=#{item.relationId} then #{item.stockNum}
                    </if>
                   </foreach>
               </trim>
               <trim prefix="stock_spare =case" suffix="end,">
                   <foreach collection="list" item="item" index="index">
                       <if test="item.stockSpare !=null and item.stockSpare != -1">
                         when relation_id=#{item.relationId} then #{item.stockSpare}
                    </if>
                   </foreach>
               </trim>
       </trim>
       where relation_id in
       <foreach collection="list" item="item" index="index" separator="," open="(" close=")">
           #{item.relationId}
       </foreach>
    </update>

另一个种写法参考:public int updateDeptChildren(@Param("depts") List<SysDept> depts);

<update id="updateDeptChildren" parameterType="java.util.List">
   update sys_dept set ancestors =
   <foreach collection="depts" item="item" index="index" separator=" " open="case dept_id" close="end">
       when #{item.deptId} then #{item.ancestors}
   </foreach>
   where dept_id in
   <foreach collection="depts" item="item" index="index" separator="," open="(" close=")">
       #{item.deptId}
   </foreach>
</update>

批量新增:public int batchMaterialInStorageDList(List<MaterialInStorageD> storageDList);

<insert id="batchMaterialInStorageDList">
		insert into material_in_storage_d(
				row_id, parent_id,product_id, product_no, update_date, model_id, actual_width, lot,remark
			) values
		<foreach item="item" index="index" collection="list" separator=",">
			(#{item.rowId},
			#{item.parentId},
			#{item.productId},
			#{item.productNo},
			#{item.updateDate},
			#{item.modelId},
			#{item.actualWidth},
			#{item.lot},
			#{item.remark}
			)
		</foreach>
	</insert>

二:批量同步,请参考下面链接:

Java把数据同步到Mysql数据库和Oracle数据库(存在更新,不存在新增)

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值