MybatisPlus批量更新

2021-10-11 15:40:51 字數 1842 閱讀 7680

在這裡插一條記錄update一次,效能比較差,容易造成阻塞。

mysql沒有提供直接的方法來實現批量更新,但可以使用case when語法來實現這個功能。

update course

set name = case id

when 1 then 'name1'

when 2 then 'name2'

when 3 then 'name3'

end,

title = case id

when 1 then 'new title 1'

when 2 then 'new title 2'

when 3 then 'new title 3'

endwhere id in (1,

2,3)

這條sql的意思是,如果id為1,則name的值為name1,title的值為new title1;依此類推。

在mybatis中的配置則如下:

"updatebatch" parametertype=

"list"

>

update course

"set" suffixoverrides=

",">

"peopleid =case" suffix=

"end,"

>

"list" item=

"i" index=

"index"

>

<

if test=

"i.peopleid!=null"

>

when id=# then #

>

<

/foreach>

<

/trim>

" roadgridid =case" suffix=

"end,"

>

"list" item=

"i" index=

"index"

>

<

if test=

"i.roadgridid!=null"

>

when id=# then #

>

<

/foreach>

<

/trim>

"type =case" suffix=

"end,"

>

"list" item=

"i" index=

"index"

>

<

if test=

"i.type!=null"

>

when id=# then #

>

<

/foreach>

<

/trim>

"unitsid =case" suffix=

"end,"

>

"list" item=

"i" index=

"index"

>

<

if test=

"i.unitsid!=null"

>

when id=# then #

>

<

/foreach>

<

/trim>

<

/trim>

where

"list" separator=

"or" item=

"i" index=

"index"

>

id=#

<

/foreach>

<

/update>

MybatisPlus批量更新

1 我們使用mybatis批量更新時,通常是這樣的 void batchupdatedemo param list listlist xml update demo table set a when then b when then where id in 欄位少的時候可以接受 但是一多就emmm....

Mybatis Plus 下批量儲存比較

mybatis 1.前端用list post了同一張表的批量資料,可用阿里的fastjson外掛程式接收處理資料 com.alibaba fastjson 1.2.47 後端接收的時候如下處理 public object classname requestbody string body retur...

mybatis plus批量操作語句格式

insert into table1 name column1 column2 column3 columnn select column1 column2 column3 columnn from table2 name ch name,en name values set ch name en ...