标签:hql
要实现新闻的上一篇下一篇功能,关键是HQL语句
上一篇:HQL="from News d where d.id<? order by id desc";
下一篇:HQL="from News d where d.id>? order by id asc ";
daoImpl实现的方法:
public News nextPage(News news){ try{ String queryString="from News d where d.id<? order by id desc"; Query queryObject=getSession().createQuery(queryString); queryObject.setLong(0,news.getId()); queryObject.setFirstResult(0); queryObject.setMaxResults(1);<pre name="code" class="java">public News nextPage(News news) { try { String queryString = "from News d where d.id>? order by id asc"; Query queryObject = getSession().createQuery(queryString); queryObject.setLong(0,news.getId()); queryObject.setFirstResult(0); queryObject.setMaxResults(1); return (News)queryObject.list().get(0); } catch (RuntimeException re) { throw re; } }
标签:hql
原文地址:http://blog.csdn.net/nethackatschool/article/details/42217333