利用Mybatis怎么對(duì)數(shù)據(jù)庫(kù)進(jìn)行批量修改

這篇文章將為大家詳細(xì)講解有關(guān)利用Mybatis怎么對(duì)數(shù)據(jù)庫(kù)進(jìn)行批量修改,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

創(chuàng)新互聯(lián)建站-成都網(wǎng)站建設(shè)公司,專注成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、網(wǎng)站營(yíng)銷推廣,國(guó)際域名空間,網(wǎng)頁(yè)空間,綿陽(yáng)服務(wù)器托管有關(guān)企業(yè)網(wǎng)站制作方案、改版、費(fèi)用等問(wèn)題,請(qǐng)聯(lián)系創(chuàng)新互聯(lián)建站。

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ù)說(shuō)明---

collection:表示類型,就寫成array,如果是集合,就寫成list

 item  : 是一個(gè)變量名,自己隨便起名

2.這種方式,可以一次執(zhí)行多條SQL語(yǔ)句

<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>屬性說(shuō)明-------

1.prefix,suffix 表示在trim標(biāo)簽包裹的部分的前面或者后面添加內(nèi)容
2.如果同時(shí)有prefixOverrides,suffixOverrides 表示會(huì)用prefix,suffix覆蓋Overrides中的內(nèi)容。
3.如果只有prefixOverrides,suffixOverrides 表示刪除開(kāi)頭的或結(jié)尾的xxxOverides指定的內(nèi)容。

關(guān)于利用Mybatis怎么對(duì)數(shù)據(jù)庫(kù)進(jìn)行批量修改就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

網(wǎng)站欄目:利用Mybatis怎么對(duì)數(shù)據(jù)庫(kù)進(jìn)行批量修改
分享路徑:http://bm7419.com/article34/pcoepe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)商城網(wǎng)站、、網(wǎng)站營(yíng)銷、企業(yè)網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)