Mybatis批量更新插入資料

2021-08-21 10:51:04 字數 898 閱讀 5036

熊大最近發現乙個批量更新時不用迴圈欄位的更新,跟各位撰碼人分享分享。同為碼農深知碼農不易,勿入坑。

好了咱們來說正事兒,來看看這條sql

update mydata_table 

set status=

when # then #

where id in

#

這無非就是根據id批量修改了mydata_table這張表的status欄位,熊大覺得寫的有點過於複雜了,如果欄位多了就會**冗餘,不方便管理。咱們在看看下面這條i

update t_order

status= #

id = #

迴圈整個sql進行對映而不是乙個字段,這樣看著是很爽,有個坑啊,我就往裡面跳了2個小時才爬出來

咱們這樣寫固然是好,條件是配置資料庫連線池druid wallfilter

@autowired

wallfilter wallfilter;

@bean(name = "dcdatasource")

@primary

public datasource getdatasourcedc() throws sqlexception

@bean(name = "wallconfig")

wallconfig wallfilterconfig()

@bean(name = "wallfilter")

@dependson("wallconfig")

wallfilter wallfilter(wallconfig wallconfig)

至於配置這個不懂得可以度一下詳情的帖子還是很多很好的。

mybatis批量插入,批量更新

insert into t ingco trade lithium electric product product no,li e product no,transpor report number,msds,transpor report number path,msds path,un tes...

mybatis 批量插入 ,更新總結

以下是在專案中運用到 的運用mybatis 批量 更新,插入的方法 注意 1 在程式中封裝了乙個list集合物件,然後需要把該集合中的實體插入到資料庫中 所以,該配置中 傳遞的引數型別 parametertype 為list foreach的主要用在構建in條件中,它可以在sql語句中進行迭代乙個集...

Mybatis批量插入或更新

1 更新單條記錄 update course set name course1 whereid id1 2 更新多條記錄的同乙個欄位為同乙個值 update course set name course1 where id in id1 id2 id3 3 更新多條記錄為多個欄位為不同的值 比較普通...