问题
I need to use DynamoDBAutoGeneratedKey from the AWS SDK to give me a random key(of type String) that I can then use to do something. I can't find any examples online of doing this, and while it seems like it should be relatively straightforward I am really struggling to get this working. Can anyone link me to an example of this being used?
回答1:
Found easy answer.
String uniqueID = UUID.randomUUID().toString();
Screw using DynamoDBAutoGeneratedKey, sounds like a headache.
回答2:
@DynamoDBTable( tableName = "Details")
public class Details
{
@DynamoDBGeneratedUuid( DynamoDBAutoGenerateStrategy.CREATE )
private UUID id;
....
@DynamoDBHashKey(attributeName = "id")
@DynamoDBAutoGeneratedKey
public UUID getId()
{
return id;
}
// also you need to add the setter otherwise you will get an exception
public void setId(UUID id)
{
this.id = id;
}
...
来源:https://stackoverflow.com/questions/37912236/how-do-i-use-dynamodbautogeneratedkey-to-give-me-an-auto-generated-key