1 回答
TA贡献1862条经验 获得超6个赞
无法为 设置区域偏移量@DynamoDBAutoGeneratedTimestamp,但可以创建您自己的@DynamoDBAutoGenerator实现以及相应的注释。
以下是您将如何在 Java 中完成它。(看起来您使用的是 Kotlin,但转换它应该很简单。)
@DynamoDBAutoGenerated(generator=AutoGeneratedTimestampWithOffset.Generator.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface AutoGeneratedTimestampWithOffset {
/**
* See {@link ZoneOffset#of(String)} for valid values.
*/
String offset();
DynamoDBAutoGenerateStrategy strategy() default DynamoDBAutoGenerateStrategy.ALWAYS;
public class Generator implements DynamoDBAutoGenerator<String> {
private final String offset;
private final DynamoDBAutoGenerateStrategy strategy;
public Generator(final Class<String> targetType, final AutoGeneratedTimestampWithOffset annotation) {
this.offset = annotation.offset();
this.strategy = annotation.strategy();
}
@Override
public DynamoDBAutoGenerateStrategy getGenerateStrategy() {
return strategy;
}
@Override
public final String generate(final String currentValue) {
return OffsetDateTime.ofInstant(Instant.now(), ZoneOffset.of(offset)).toString();
}
}
}
在你的@DynamoDBTable课堂上,你会像这样使用这个注解:
@get:AutoGeneratedTimestampWithOffset(offset="+05:30", strategy=DynamoDBAutoGenerateStrategy.CREATE)
var createdAt: String? = null
@get:AutoGeneratedTimestampWithOffset(offset="+05:30", strategy=DynamoDBAutoGenerateStrategy.ALWAYS)
var updateAt: String? = null
添加回答
举报