34人参与 • 2025-08-23 • Java
<update id="updatenrpurchaseorderdetailbygoodsbarcode"> update nr_purchase_order_detail set stored_num = <foreach collection="barcodelist" item="item" index="index" separator=" " open="case goods_barcode" close="end"> when #{item.barcode} then stored_num + #{item.receivenum} </foreach> ,unstored_num = <foreach collection="barcodelist" item="item" index="index" separator=" " open="case goods_barcode" close="end"> when #{item.barcode} then actual_goods_num - stored_num </foreach> where goods_barcode in <foreach collection="barcodelist" item="item" index="index" separator="," open="(" close=")"> #{item.barcode} </foreach> and parent_id = #{id} </update>
<!--casewhen形式更新--> <update id="testcasewhen" parametertype="java.util.map"> update ${user} <set> <trim prefix="id= case id" suffix="end,"> <foreach collection="list" item="param"> <if test="param.id != null and id != ''"> when #{param.id} then #{param.id} </if> </foreach> </trim> <trim prefix="username = case id" suffix="end,"> <foreach collection="list" item="param"> <if test="param.username != null and param.username != ''"> when #{param.} then #{param.username} </if> </foreach> </trim> <trim prefix="password = case id" suffix="end,"> <foreach collection="list" item="param"> <if test="param.password != null and param.password != ''"> when #{param.id} then #{param.password} </if> </foreach> </trim> </set> <where> id in <foreach collection="list" item="param" separator="," open="(" close=")"> #{param.id} </foreach> </where> </update>
上述第一个示例中,按照条码进行批量更新,将所有的条码对应的入库数量和剩余数量进行更新。
第二个示例中,又使用了set标签和trim标签,感觉更为复杂。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论