1 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個贊
無法為 設(shè)置區(qū)域偏移量@DynamoDBAutoGeneratedTimestamp,但可以創(chuàng)建您自己的@DynamoDBAutoGenerator實(shí)現(xiàn)以及相應(yīng)的注釋。
以下是您將如何在 Java 中完成它。(看起來您使用的是 Kotlin,但轉(zhuǎn)換它應(yīng)該很簡單。)
@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
添加回答
舉報