Mybatis批量修改的操作代碼
1.修改的字段值都是一樣的,id不同
<update id="batchUpdate" parameterType="String"> update cbp_order set status=1 where id in <foreach item="id" collection="array" open="(" separator="," close=")"> #{id} </foreach> </update> ---參數(shù)說明---
collection:表示類型,就寫成array,如果是集合,就寫成list
?item? : 是一個(gè)變量名,自己隨便起名
2.這種方式,可以一次執(zhí)行多條SQL語句
<update id="batchUpdate" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update test <set> test=#{item.test}+1 </set> where id = #{item.id} </foreach> </update>
3.整體批量更新
<update id="updateBatch" parameterType="java.util.List"> update mydata_table <trim prefix="set" suffixOverrides=","> <trim prefix="status =case" suffix="end,"> <foreach collection="list" item="item" index="index"> <if test="item.status !=null and item.status != -1"> when id=#{item.id} then #{item.status} </if> <if test="item.status == null or item.status == -1"> when id=#{item.id} then mydata_table.status//原數(shù)據(jù) </if> </foreach> </trim> </trim> where id in <foreach collection="list" index="index" item="item" separator="," open="(" close=")"> #{item.id,jdbcType=BIGINT} </foreach> </update> ----<trim>屬性說明-------
1.prefix,suffix 表示在trim標(biāo)簽包裹的部分的前面或者后面添加內(nèi)容
2.如果同時(shí)有prefixOverrides,suffixOverrides 表示會(huì)用prefix,suffix覆蓋Overrides中的內(nèi)容。
3.如果只有prefixOverrides,suffixOverrides 表示刪除開頭的或結(jié)尾的xxxOverides指定的內(nèi)容。
總結(jié)
以上所述是小編給大家介紹的Mybatis批量修改的操作代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
java實(shí)現(xiàn)基于UDP協(xié)議網(wǎng)絡(luò)Socket編程(C/S通信)
這篇文章主要介紹了java實(shí)現(xiàn)基于UDP協(xié)議網(wǎng)絡(luò)Socket編程(C/S通信),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10SpringBoot應(yīng)用整合ELK實(shí)現(xiàn)日志收集的示例代碼
這篇文章主要介紹了SpringBoot應(yīng)用整合ELK實(shí)現(xiàn)日志收集的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09學(xué)習(xí)Java之二叉樹的編碼實(shí)現(xiàn)過程詳解
本文將通過代碼來進(jìn)行二叉樹的編碼實(shí)現(xiàn),文中的代碼示例介紹的非常詳細(xì),對(duì)我們學(xué)習(xí)Java二叉樹有一定的幫助,感興趣的同學(xué)跟著小編一起來看看吧2023-08-08Spring?BOOT?AOP基礎(chǔ)應(yīng)用教程
這篇文章主要介紹了Spring?BOOT?AOP的使用,文章從相關(guān)問題展開全文內(nèi)容詳情,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-07-07