spring ibatis 批量提交資料

2021-06-14 00:17:25 字數 540 閱讀 9713

在系統中,提取資料迴圈計算後,每次需要有大概3000條左右的資料需要提交到資料庫。以前在迴圈中單條插入,開始只有200條左右的資料,看不出效能上的問題,現在資料量增長了很多,所以需要對提交功能做一下優化。spring整合了ibatis的批量提交的功能,我們只要呼叫api就可以了 

首先在你的dao中需要繼承org.springframework.orm.ibatis.support.sqlmapclientdaosupport 

然後在**中呼叫getsqlmapclienttemplate方法, 覆寫sqlmapclientcallback類中的doinsqlmapclient的方法 

public void inserttreecatebatch(final listtreecatelist) throws dataacces***ception 

} executor.executebatch(); 

return null; 

} }); 

} 批量插入減少了獲取資料庫連線池的次數,經過測試可以提高60%到70%的效能,大家不妨在專案中使用一下。

Spring Ibatis批量效能

1.按需取資料,減少網路開銷。a 表 有 100 多個字段,儲存在資料庫 a 上 id property1 property2 property120 b 表 只有 10 個字段,儲存在資料庫 b 上 id property1 property2 property10 要從 a 表中查詢一些資料在插...

spring ibatis 批量處理資料

本人在最近的專案中發現這樣的乙個問題。在spring ibatis的配置下,存在多種進行資料操作的方法。各種方法在效率上以及是否存在潛在bug上,也各不相同。以下述 為例 public void insert siterank param public void insertall listsite...

Spring ibatis批量儲存心得

程式功能 使用ibatis spring將oracle資料庫中的tfile表中的資料抽取到db2資料庫的tfile表,這兩個表的結構相同。測試環境 celeron m 1.4 512m mysql 5.0資料庫 public static void main string args test2fil...