hibernate 时间段查询
方法1
@Override
public int findIfLoginAlreadyLogin() {
Date now = new Date();
List<RevitLoginlog> result = getCurrentSession().createQuery("from RevitLoginlog where loginTime >=:beginTime and loginTime<=:endTime")
.setTimestamp("beginTime", DateUtils.getStartDate(now)).setTimestamp("endTime", DateUtils.getFinallyDate(now)).list();
return result != null && result.size() > 0 ? 1 : 0;
}
方法2
@SuppressWarnings("unchecked")
@Override
public List<Order> calcDeveloperMoney(Long year, Long month, Long reqId, Long staffId) {
String hql = "from Order t where t.revitAddInId = (select m.id from RevitAddIn m where m.reqId = :reqId) "+
"and t.status=1 and t.staffId=:staffId and t.createTime between :beginTime and :endTime ";
Date[] dates= getQueryTime(year, month);
List<Order> data = getCurrentSession().createQuery(hql).setLong("staffId", staffId).
setLong("reqId", reqId).setDate("beginTime",dates[0]).setDate("endTime",dates[1]).list();
return data;
}