Spring+ ibatis批量插入数据

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;
}
});
}

你可能感兴趣的:(spring,ibatis,数据,插入)