使用 JDOQL 过滤开始日期和结束日期之间的日期属性
我想编写一个函数来获取 Entry
对象的列表,其 date
字段位于 beginPeriod
和 endPeriod
之间我在下面发布了一个与 HACK 一起使用的代码片段。我必须从开始日期中减去一天。看来伟大或等于的条件不起作用。
知道为什么我会遇到这个问题吗?
public static List<Entry> getEntries(Date beginPeriod, Date endPeriod) {
/* TODO
* The great or equal condition does not seem to work in the filter below
* Substract a day and it seems to work
*/
Calendar calendar = Calendar.getInstance();
calendar.set(beginPeriod.getYear(), beginPeriod.getMonth(), beginPeriod.getDate() - 1);
beginPeriod = calendar.getTime();
PersistenceManager pm = JdoUtil.getPm();
Query q = pm.newQuery(Entry.class);
q.setFilter("this.date >= beginPeriodParam && this.date <= endPeriodParam");
q.declareParameters("java.util.Date beginPeriodParam, java.util.Date endPeriodParam");
List<Entry> entries = (List<Entry>) q.execute(beginPeriod,endPeriod);
return entries;
}
I want to code a function to get a list of Entry
objects whose date
field is between a beginPeriod
and endPeriod
I post below a code snippet which works with a HACK. I have to substract a day from the begin period date. It seems the condition great or equal does not work.
Any idea why I have this issue?
public static List<Entry> getEntries(Date beginPeriod, Date endPeriod) {
/* TODO
* The great or equal condition does not seem to work in the filter below
* Substract a day and it seems to work
*/
Calendar calendar = Calendar.getInstance();
calendar.set(beginPeriod.getYear(), beginPeriod.getMonth(), beginPeriod.getDate() - 1);
beginPeriod = calendar.getTime();
PersistenceManager pm = JdoUtil.getPm();
Query q = pm.newQuery(Entry.class);
q.setFilter("this.date >= beginPeriodParam && this.date <= endPeriodParam");
q.declareParameters("java.util.Date beginPeriodParam, java.util.Date endPeriodParam");
List<Entry> entries = (List<Entry>) q.execute(beginPeriod,endPeriod);
return entries;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是因为数组从 0 开始。我试图你的(我的查询没有返回任何内容??)并注意到它已经持续了几个月 - 1 =>;二月,4=>五月,等等。
my guess is it's because arrays begin at 0. i was trying to your (my query doesn't return anything??) and noticed that it's true for months - 1 => february, 4=>may, etc.