大於,小於,等於,大於等於,小於等於
public List<實體類> getBetweenStartDateAndEndDate( Session session, int id, DateTime startDateTime, DateTime endDateTime) { DateTime endDate = endDateTime.plusDays(1);//查詢日期必須要加1天,不然查不到今天創建的記錄,要考慮23:59:59秒的問題 StringBuffer hql = new StringBuffer( "FROM 實體類 WHERE poolid = '" + id + "' AND createDt >= '" + startDateTime.toString("yyyy-MM-dd") + "' AND createDt <'" + endDate.toString("yyyy-MM-dd") + "' ORDER BY id ASC"); Query query = session.createQuery(hql.toString()); List<實體類> cps = query.list(); return cps; }