下面給大家介紹mybatis批量更新報(bào)錯(cuò)問(wèn)題,
1
|
allowMultiQueries= true |
后來(lái)發(fā)現(xiàn)是jdbc鏈接沒(méi)有加允許批量更新操作的參數(shù)引起的,不加會(huì)報(bào)badsql,mysql版的mybatis批量更新操作如下
1
2
3
4
5
6
7
8
9
|
<update id= "updateOrderOverdueStatus" parameterType= "java.util.List" > <foreach collection= "list" item= "item" index= "index" open= "" close= "" separator= ";" > update t_am_bystages_order <set> overdue_status=#{item.overdueStatus} </set> where order_id=#{item.orderId} </foreach> </update> |
下面看下Mybatis批量更新數(shù)據(jù)的方式
第一種方式
1
2
3
4
5
6
7
8
9
|
<update id= "updateBatch" parameterType= "Map" > update aa set a=#{fptm}, b=#{csoftrain} where c in <foreach collection= "cs" index= "index" item= "item" pen= "(" separator= "," close= ")" > #{item} </foreach> </update> |
但是這種方式修改的字段值都是一樣的。
第二種方式
修改數(shù)據(jù)庫(kù)連接配置:&allowMultiQueries=true
比如:jdbc:MySQL://192.168.1.236:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
1
2
3
4
5
6
7
8
9
|
<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> |
這種方式,可以一次執(zhí)行多條SQL語(yǔ)句
參考:
mybatis執(zhí)行批量更新batch update 的方法(oracle,mysql兩種)
以上所述是小編給大家介紹的詳解Mybatis批量更新報(bào)錯(cuò),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!