一:批量修改
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数据库(存在更新,不存在新增)