批量新增数据:
<insert id="batchPutInfo" parameterType="com.cdtye.kmims.computer.model.entity.ComputerGoodsPutInfo">
insert into COMPUTER_GOODS_PUT_INFO(ID,PUT_IN_ID,PURCHASE_NUM,SELF_NO,GOODS_NAME,MODEL_SPEC,
COMMODITY_CATEGORY,THIRD_CATEGORY,COMMODITY_NAME,PUT_IN_NUM,REMARK)
<foreach collection="list" item="item" separator="UNION ALL">
SELECT #{item.id},#{item.putInId},#{item.purchaseNum},#{item.selfNo},#{item.goodsName},#{item.modelSpec},
#{item.commodityCategory},#{item.thirdCategory},#{item.commodityName},#{item.putInNum},#{item.remark}
FROM dual
</foreach>
</insert>
批量更新数据:
<update id="batchUpdateRepairInfo">
<foreach collection="list" item="item" index="index" separator=";" open="begin" close=";end;">
UPDATE COMPUTER_GOODS_REPAIR_INFO SET REPAIR_METHOD = #{item.repairMethod},
REPAIR_RESULT = #{item.repairResult},RETURN_REMARK = #{item.returnRemark}
WHERE ID = #{item.id}
</foreach>
</update>

文章展示了两个数据库操作示例,一个是批量新增商品入库信息,使用<insert>标签并结合<foreach>遍历列表进行UNIONALL操作;另一个是批量更新商品维修信息,通过<update>标签和<foreach>更新多条记录,基于ID匹配。

1万+

被折叠的 条评论
为什么被折叠?



