2

我已经看到了使用 ArrayList 进行批量更新的代码,如下所示:

@Override
public void saveBatch(final List<Employee> employeeList) {
    final int batchSize = 500;

    for (int j = 0; j < employeeList.size(); j += batchSize) {

        final List<Employee> batchList = employeeList.subList(j, j + batchSize > employeeList.size() ? employeeList.size() : j + batchSize);

        getJdbcTemplate().batchUpdate(QUERY_SAVE,
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i)
                        throws SQLException {
                    Employee employee = batchList.get(i);
                    ps.setString(1, employee.getFirstname());
                    ps.setString(2, employee.getLastname());
                    ps.setString(3, employee.getEmployeeIdOnSourceSystem());
                }

                @Override
                public int getBatchSize() {
                    return batchList.size();
                }
            });

    }
}

但是如果我像下面这样使用Hashmap:HashMap<String, VerifyPaymentRO> verifyPaymentInfoMap

VerifyPaymentRO是java bean

我如何使用它来更新记录?

4

1 回答 1

1

只需List<?>从地图值创建出来,您就可以使用您发布的相同代码:

List<VerifyPaymentRO> verifyPaymentList = new ArrayList<>(verifyPaymentInfoMap.values());
于 2013-10-04T12:43:26.350 回答