如何使用java对Amazon dynamodb中的数据进行排序

如何使用java对Amazon dynamodb中的数据进行排序,java,amazon-web-services,sorting,amazon-dynamodb,amazon,Java,Amazon Web Services,Sorting,Amazon Dynamodb,Amazon,如何使用java对amazon dynamodb中的countryCode列数据进行升序或降序排序 如何在代码中使用排序器枚举 SortOrder枚举可在packagecom.amazonaws.services.codedeploy.model.SortOrder中找到 您无法对countryCode进行排序,因为上面没有一个。在应用程序中,您必须使用获取所有行并对数据进行排序 旁注:countryCode不是DynamoDB中的一列-它是一个属性。有关更多信息,请参阅。是什么让您认为com.

如何使用java对amazon dynamodb中的countryCode列数据进行升序或降序排序

如何在代码中使用排序器枚举

SortOrder枚举可在packagecom.amazonaws.services.codedeploy.model.SortOrder中找到

您无法对countryCode进行排序,因为上面没有一个。在应用程序中,您必须使用获取所有行并对数据进行排序


旁注:countryCode不是DynamoDB中的一列-它是一个属性。有关更多信息,请参阅。

是什么让您认为com.amazonaws.services.codedeploy.model.SortOrder将用于DynamoDB?AWS SDK基本上是按服务划分的。@MikeKobit在SortOrder类中,它包含Ascendingascending,DecendingDescending;。您能告诉我如何在java中按升序/降序对countryCode列数据进行排序吗?SortOrder是特定于的。正如我在回答中所说,您需要使用扫描操作来读取整个表,并将结果拉入内存,在内存中您必须对其进行排序。另一个选项是使用在表上创建索引,然后您可以使用查询操作获取有序结果,并且您可以在不必先读取整个表的情况下分页。@MikeKobit您可以发布代码吗。
import java.io.Serializable;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;

@DynamoDBTable(tableName = "cd_country")
public class Country implements Serializable {

    private static final long serialVersionUID = 5698425418072128936L;

    @DynamoDBAutoGeneratedKey
    @DynamoDBHashKey
    private String countryId;

    private String countryCode;

    private String countryName;

    private Long isActive;

    public String getCountryId() {
        return countryId;
    }

    public void setCountryId(String countryId) {
        this.countryId = countryId;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public String getCountryName() {
        return countryName;
    }

    public void setCountryName(String countryName) {
        this.countryName = countryName;
    }

    public Long getIsActive() {
        return isActive;
    }

    public void setIsActive(Long isActive) {
        this.isActive = isActive;
    }

}