Spring+ ibatis批量插入数据

来源:互联网 发布:微小企业会计软件好吗? 编辑:程序博客网 时间:2024/05/01 14:15

1:class extends SqlMapClientDaoSupport

2:

@Resource(name = "sqlMapClient")

private SqlMapClient sqlMapClient;
@PostConstruct        

public void initSqlMapClient(){
 super.setSqlMapClient(sqlMapClient);    
 }

3:

@SuppressWarnings({ "unchecked", "rawtypes" })

public void insertRecordByList(final List<ExamecardModel> examecardList) {
this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {
executor.startBatch();
// 每次提交最大条数
final int batchSize = 100000;
int count = 0;
for (ExamecardModel record : examecardList) {
executor.insert("com.test.dao.testDao.test", record);
// 每10000条数据提交一次
if (++count % batchSize == 0) {
executor.executeBatch();
}
}
// 提交剩余的数据
executor.executeBatch();
return null;
}
});
}
0 0
原创粉丝点击