【发布时间】:2018-09-11 14:46:12
【问题描述】:
我可以使用以下代码在 DynamoDB 中插入一个对象(使用 @DynamoDBTable 注释)
@Autowired
private SdnInformationRepository sdnInformationRepository;
SdnInformation inf = new SdnInformation();
inf.setFirstName("firstname");
inf.setLastName("lastname");
sdnInformationRepository.save(inf);
这是我的仓库
public interface SdnInformationRepository extends
CrudRepository<SdnInformation, String> {
}
还有我的模特
@DynamoDBTable(tableName = "SdnList")
public class SdnInformation {
@DynamoDBHashKey(attributeName = "Id")
@DynamoDBAutoGeneratedKey
private String id;
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
这里一切正常。我想知道是否可以一次插入一个列表/一组 SdnInformation 对象?如果我单独插入大量此类对象,则需要花费太多时间。 所以我想要类似的东西
Set<SdnInformation> listToInsert = new HashSet<SdnInformation>();
... some code to fill my set with thousands of objects ...
sdnInformationRepository.save(listToInsert);
【问题讨论】:
-
CrudRepository 接口有一个 saveAll 方法...
-
哇!我错过了。 saveAll 方法完成了这项工作!
标签: java database insert save amazon-dynamodb