DynamoDB 映射器只在一个项目中保存一个属性 Java
DynamoDB mapper save only one attribute in an item Java
我正在从我的 dynamodb table 中获取一个项目记录,添加一个属性(userratings),然后像这样再次保存它:
SongDatabaseMappingAdapter song = mapper.load(SongDatabaseMappingAdapter.class, params[0]);
song.getUserRatings().add(userID + "-" + params[1] + "-" + sdf.format(date));
mapper.save(song);
问题出在我的 SongDatabaseMappingAdapter 中,我有一些额外的 getter setter 用于更新 GUI,如下所示:
public Boolean getOneStarRating() {
return onestarrating;
}
public void setOneStarRating(Boolean onestarrating) {
this.onestarrating = onestarrating;
}
我需要它们存在,但我不希望它们保存到我数据库中的属性,但是当我 运行 我保存项目的代码添加了所有属性,这是每个元素我的 getter/setter(映射适配器)进入项目,所以我最终得到如下所示的额外属性(列)(下面的所有星级评分都已添加但不应该存在):
UserRatings fiveStarRating fourStarRating oneStarRating
所以基本上我想更改我的代码,以便它只保存歌曲项目中的 userratings 属性,而不是所有属性。我在想像下面这样的东西,但我不确定该怎么做(下面的代码不起作用)
SongDatabaseMappingAdapter song = mapper.load(SongDatabaseMappingAdapter.class, params[0]);
song.getUserRatings().add(userID + "-" + params[1] + "-" + sdf.format(date));
mapper.save(song.setUserRatings());
感谢您的帮助
用@DynamoDBIgnore
注释额外的属性。根据文档 here:
DynamoDBIgnore
Indicates to the DynamoDBMapper instance that the associated property
should be ignored. When saving data to the table, the DynamoDBMapper
does not save this property to the table.
我正在从我的 dynamodb table 中获取一个项目记录,添加一个属性(userratings),然后像这样再次保存它:
SongDatabaseMappingAdapter song = mapper.load(SongDatabaseMappingAdapter.class, params[0]);
song.getUserRatings().add(userID + "-" + params[1] + "-" + sdf.format(date));
mapper.save(song);
问题出在我的 SongDatabaseMappingAdapter 中,我有一些额外的 getter setter 用于更新 GUI,如下所示:
public Boolean getOneStarRating() {
return onestarrating;
}
public void setOneStarRating(Boolean onestarrating) {
this.onestarrating = onestarrating;
}
我需要它们存在,但我不希望它们保存到我数据库中的属性,但是当我 运行 我保存项目的代码添加了所有属性,这是每个元素我的 getter/setter(映射适配器)进入项目,所以我最终得到如下所示的额外属性(列)(下面的所有星级评分都已添加但不应该存在):
UserRatings fiveStarRating fourStarRating oneStarRating
所以基本上我想更改我的代码,以便它只保存歌曲项目中的 userratings 属性,而不是所有属性。我在想像下面这样的东西,但我不确定该怎么做(下面的代码不起作用)
SongDatabaseMappingAdapter song = mapper.load(SongDatabaseMappingAdapter.class, params[0]);
song.getUserRatings().add(userID + "-" + params[1] + "-" + sdf.format(date));
mapper.save(song.setUserRatings());
感谢您的帮助
用@DynamoDBIgnore
注释额外的属性。根据文档 here:
DynamoDBIgnore
Indicates to the DynamoDBMapper instance that the associated property should be ignored. When saving data to the table, the DynamoDBMapper does not save this property to the table.