我正在尝试使用spring-data-dynamodb。我桌上已经有一些物品了。我正在尝试通过ID日期和日期时间对它们进行排序。我的豆子看起来像下面的
@DynamoDBTable(tableName = "TableName")
public class TableName {
@Id
private IDTable id;
private String hashkey;
private LocalDateTime createdTime;
private List<Map<String, AttributeValue>> records;
private String createdBy;
@DynamoDBHashKey(attributeName = "hashkey")
public String getHashkey() {
return id != null ? id.getHashkey() : null;
}
public void setHashkey(String hashkey) {
if(id == null) {
id = new IDTable();
}
id.setHashkey(hashkey);
}
@DynamoDBRangeKey(attributeName = "created_time")
@DynamoDBTypeConverted(converter = LocalDateTimeConverter.class)
public LocalDateTime getCreatedTime() {
return id.getCreatedTime() != null ? id.getCreatedTime() : null;
}
public void setCreatedTime(LocalDateTime createdTime) {
if(id == null) {
id = new IDTable();
}
id.setCreatedTime(createdTime);
}
@DynamoDBAttribute(attributeName = "records")
public List<Map<String, AttributeValue>> getRecords() {
return records;
}
public void setRecords(List<Map<String, AttributeValue>> records) {
this.records = records;
}
@DynamoDBAttribute(attributeName = "created_by")
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
static public class LocalDateTimeConverter implements DynamoDBTypeConverter<String, LocalDateTime> {
@Override
public String convert(final LocalDateTime time) {
return time.toString();
}
@Override
public LocalDateTime unconvert(final String stringValue) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSz");
return LocalDateTime.parse(stringValue, formatter);
}
}
}
在我的存储库中,我定义了以下方法
List<TableName> findByHashkey(String hashKey,Sort sort);
我希望记录按createdTime排序,但createdTime被认为是字符串而不是LocalDateTime,并且我按字符串排序来获取所有记录。我需要将它们按日期排序。