思路一:java实现
通过Batch操作,实现insert和update的批处理。
public class BaseLevelAccessDAOImpl extends SqlMapClientDaoSupport {
public void insertBaseLevelDefine(final List<BaseLevelDefineDO> list) {
if (null == list) {
throw new IllegalArgumentException("Can't insert a null data object into db.");
}
SqlMapClientCallback callback = new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (BaseLevelDefineDO item : list) {
executor.insert("BASE-LEVEL-DEFINE-INSERT", item);
}
executor.executeBatch();
return null;
}
};
getSqlMapClientTemplate().execute(callback);
}
public void updateBaseLevelData(final List<BaseLevelDataDO> list) {
if (list == null) {
throw new IllegalArgumentException("Can't update by a null data object.");
}
SqlMapClientCallback callback = new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (BaseLevelDataDO tObject : list) {
executor.update("BASE-LEVEL-DATA-UPDATE", tObject);
}
executor.executeBatch();
return null;
}
};
getSqlMapClientTemplate().execute(callback);
}
}
xml配置实现
xml实现了insert,update不知怎么弄。
<!-- mapped statement for BaseLevelAccessDAO.insertBaseLevelDefine -->
<insert id="BASE-LEVEL-DEFINE-INSERT" parameterClass="java.util.List">
<![CDATA[ insert all ]]>
<iterate conjunction=" " >
<![CDATA[into test_table (ID,CUSTOM_TABLE_ID, FIELD,ENV,UNIMARK, GMT_CREATE) values (#list[].id#,#list[].customTableId#, #list[].field#, #list[].env#, #list[].unimark#, sysdate) ]]>
</iterate>
<![CDATA[select * from dual ]]>
</insert>