日期:2014-05-19 浏览次数:20743 次
/* * Find all events in the given month and year. * @param month - 0-11 (0 = January) * @param year */ public List findEventsFor(int month, int year) { List events = null; try { startOperation(); Date firstDay = DateUtils.newDate(month, 1, year); Date lastDay = DateUtils.newDate(month + 1, 1, year); StringBuffer sql = new StringBuffer(); sql.append("from Event event where 1=1 and event.startDate >= :firstDay and event.startDate < :lastDay"); Query query = getSession().createQuery(sql.toString()); query.setParameter("firstDay", firstDay); query.setParameter("lastDay", lastDay); events = query.list(); getTx().commit(); } catch (HibernateException e) { handleException(e); } finally { HibernateFactory.close(getSession()); } return events; }
StringBuffer sql = new StringBuffer(); sql.append("from Event event where 1=1 "); Query query = getSession().createQuery(q); if(null != startData && null != lastDay) { sql.append("and event.startDate >= :firstDay and event.startDate < :lastDay"); } query.setParameter("firstDay", firstDay); query.setParameter("lastDay", lastDay);