首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

Hibernate中展示前一条,后一条记录

2012-08-29 
Hibernate中显示前一条,后一条记录/*** 查询当前记录的前一条记录,并返回主键id** @author Neeao(njl) 200

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; }?

热点排行