首页  >  文章  >  数据库  >  HQL实现新闻上一篇下一篇

HQL实现新闻上一篇下一篇

WBOY
WBOY原创
2016-06-07 16:12:56903浏览

daoImpl实现的方法: public News nextPage(News news){try{String queryString=from News d where d.id? order by id desc;Q【本文来自鸿网互联 (http://www.68idc.cn)】uery queryObject=getSession().createQuery(queryString);queryObject.setLong(0,new

daoImpl实现的方法:

 

public News nextPage(News news){
		try{
			String queryString="from News d where d.id<? order by id desc";
			Q【本文来自鸿网互联 (http://www.68idc.cn)】uery 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;
		}
		
	}

return (News)queryObject.list().get(0);}catch(RuntimeException re){throw re;}}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn