Mybatis批量更新數據


         Mybatis批量更新數據                     

第一種方式

 

[html] view plain copy
 
print?
  1. <update id="updateBatch" parameterType="Map">    
  2.         update aa   set     
  3.             a=#{fptm},    
  4.             b=#{csoftrain}    
  5.         where c in     
  6.         <foreach collection="cs" index="index" item="item" open="("separator=","close=")">    
  7.             #{item}    
  8.         </foreach>  
  9. </update>  


但是這種方式修改的字段值都是一樣的。

 

第二種方式

修改數據庫連接配置:&allowMultiQueries=true

比如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&amp;characterEncoding=UTF-8&allowMultiQueries=true

 

[html] view plain copy
 
print?
  1. <update id="batchUpdate"  parameterType="java.util.List">  
  2.         
  3.           <foreach collection="list" item="item" index="index" open="" close="" separator=";">  
  4.                 update test   
  5.                 <set>  
  6.                   test=${item.test}+1  
  7.                 </set>  
  8.                 where id = ${item.id}  
  9.          </foreach>  
  10.             
  11.     </update>  


這種方式,可以一次執行多條SQL語句

 

摘錄自:http://blog.csdn.net/tolcf/article/details/39213217


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM