Hibernate中显示前一条,后一条记录
/** * 查询当前记录的前一条记录,并返回主键id * * @author Neeao(njl) 2007-7-17 * @param id * @return * @throws DAOException */ public int before(int id) throws DAOException { int strid = 0; Session session = SessionManager.getSession(); String hql = "from MailList as maillist where maillist.id<" + id + " order by maillist.id desc"; Query query = session.createQuery(hql); query.setFirstResult(0); query.setMaxResults(1); List list = query.list(); if (list != null && list.size() > 0) { MailList mailList = (MailList) list.get(0); strid = mailList.getId(); } return strid; } /** * 查询当前记录的下一条记录,并返回主键id * * @author Neeao(njl) 2007-7-17 * @param id * @return * @throws DAOException */ public int next(int id) throws DAOException { int strid = 0; Session session = SessionManager.getSession(); String hql = "from MailList as maillist where maillist.id> " + id + " order by maillist.id"; Query query = session.createQuery(hql); query.setFirstResult(0); query.setMaxResults(1); List list = query.list(); if (list != null && list.size() > 0) { MailList mailList = (MailList) list.get(0); strid = mailList.getId(); } return strid; }?