gpt4 book ai didi

java - 使用 objectify 按多列排序

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:25:58 25 4
gpt4 key购买 nike

我在想,是否有一种方法可以使用 2 列而不是一列来对查询进行排序。我很确定 query.order("param1").order("param2") 会忽略一个参数。

是否可以使用 objectify 对多列进行排序?

这是我的@Entity

@Entity
public class Operation {
@Id protected Long id;
@Index protected Long creatorId;
@Index protected Long categoryId;
@Index protected Double value;
@Index protected String description;
@Index protected Date date;
}

最佳答案

可以使用 objectify 对多列进行排序。事实上,如果您有一个正确的多属性索引,您在问题中的查询应该有效。

例如,如果您想按日期和 creatorId 对结果进行排序(从您的问题中获取这些字段),您需要在项目的“datastore-indexes.xml”文件中包含以下索引:

<datastore-index kind="Operation " ancestor="false">
<property name="date " direction="asc" />
<property name="creatorId" direction="asc" />
</datastore-index>

请注意,这只是一个例子。 “祖先”、“方向”的实际值取决于您的要求。

另一种选择是自动生成所需的索引。如果您在 GAE 开发服务器上运行您的应用程序,开发服务器会自动生成具有所需索引的数据存储索引文件 (WEB-INF/appengine-generated/datastore-indexes-auto.xml)。

您可以阅读更多相关信息 here .

关于java - 使用 objectify 按多列排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21406407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com