我想自動號碼dynamodb通過控制檯, 例如添加到表的鍵字段0,1,2,...dynamodb:如何自動遞增號添加到關鍵領域,同時增加記錄表
我有contact_us
表,我想有一個與自動識別增量列。 請幫我這個。
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
public class ContactUs extends HttpServlet {
String con_id;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try{
// ...
// ...
Map<String, AttributeValue> item = newRecord();
//System.out.println(item);
// ...
dbObject.addRecord(item, "contact_us");
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
private Map<String, AttributeValue> newRecord() {
Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
con_id = getConID();
dateTimeTimestamp = new SysDateTimeTimestamp();
//Need to add con_id which will be auto id.
item.put("con_id", new AttributeValue(con_id));
// ...
// ...
return item;
}
@DynamoDBHashKey(attributeName = "con_id")
@DynamoDBAutoGeneratedKey
public String getConID(){
return con_id;
}
public void setConID(String con_id){
this.con_id = con_id;
}
}
這裏我收到con_id值爲空白。
有幫助嗎? – notionquest