【问题标题】:How to filter on basis of JodaTime in objectify如何在objectify中基于JodaTime进行过滤
【发布时间】:2016-04-01 08:03:21
【问题描述】:

我是 Google Appengine 的新手。在我的应用程序中,数据存储实体存储 org.joda.time.DateTime 对象。我想查询数据存储以返回 2 个特定日期时间范围内的所有实体。我的代码是:

@Entity
@Cache
@Index
public class Sample {

    @Id
    Long id; // autogen

    private DateTime dateTime;
    private int activeCount;
    private int inactiveCount;
}

我想要一个类似的查询 -

 Iterable<Sample> sampleIterable = ofy().load().type(Sample.class)
                    .filter("dateTime <", DateTime.now())
                    .filter("dateTime >", DateTime.now().minusDays(1))
                    .iterable();

是否可以像这样查询 DateTime ?在 objectify 中查询 DateTime 的正确方法是什么?很抱歉没有说清楚。

【问题讨论】:

  • 您是否在您的 objectify 服务/工厂注册了 joda 日期时间翻译器?如果是这样,这应该只是工作,假设存在正确的索引(在这种情况下,'dateTime'字段用@Index标记)

标签: java google-app-engine datetime objectify


【解决方案1】:

如果您使用 Objectify 注册 Joda 翻译器,您可以使用 DateTime 作为字段和过滤子句。您也可以使用 DateTime 过滤常规的 Date 属性。

JodaTimeTranslators.add(ObjectifyService.factory());

默认情况下不启用此功能,因为每个人都需要将 joda time 作为依赖项。

【讨论】:

    猜你喜欢
    • 2022-12-06
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多