我是Google Appengine的新手。在我的应用程序中,数据存储区实体存储org.joda.time.DateTime对象。我想查询数据存储区以返回2个特定DateTime范围之间的所有实体。我的代码是:
@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
同时用作字段和filter子句。您也可以使用DateTime
过滤常规Date
属性。
JodaTimeTranslators.add(ObjectifyService.factory());
默认情况下未启用此功能,因为每个人都需要将joda时间作为依赖项。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句