这是为评估所需结果而编写的代码:
Calendar c7DaysAgo = Calendar.getInstance(); // 7 days ago
c7DaysAgo.add(Calendar.DATE, -7);
Calendar today = Calendar.getInstance(); // today
today.add(Calendar.DATE, 0);
Criteria criteria = session.createCriteria(Checkin.class)
.add(Restrictions.like("fbuid", id))
.add(Restrictions.between("date", today.getTime(), c7DaysAgo.getTime()));
List<Checkin> checkinList = criteria.list();
return checkinList.size();
要检索值的表值是:
| id | date | fbuid |号码|
| 1 | 2012-12-04 18:41:34 | 1111 | 16 |
| 2 | 2012-12-04 18:41:34 | 1111 | 2 |
我需要从今天到7天之间的行数。 但我得到的值是0而不是2。
请帮助我,因为我无法弄清楚出了什么问题!
答案 0 :(得分:0)
我意识到我的错误......两者之间的参数顺序错误......应该是
Criteria criteria = session.createCriteria(Checkin.class)
.add(Restrictions.like("fbuid", id))
.add(Restrictions.between("date", c7DaysAgo.getTime(),today.getTime()));