hql多表關聯模糊查詢
阿新 • • 發佈:2018-12-25
public Page<AlarmPushRecord> findByPage(int size, int index, String startAt, String endAt, String content) throws ParseException { DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //resove java.text.ParseException: Unparseable date: "2018-12-19 00:00:00" Date start1 = format.parse(startAt); Date end1 = format.parse(endAt); String hql = "select a from AlarmPushRecord a,Alarm b where (a.pushTime between :startAt and :endAt) and (b.id = a.alarm.id) and (b.content like :content)"; Query query = this.getHibernateSession().createQuery(hql); query.setParameter("startAt", start1); query.setParameter("endAt", end1); query.setParameter("content", "%"+content+"%"); List<Object> list = query.getResultList(); Page<AlarmPushRecord> page = new Page(index,list.size(),size,list); return page; }