取上一条下一条记录

    取上一条
   sql = " from News n where n.id < ? order by n.id desc ";
   List list = getSession().createQuery(sql);
   return list.size() > 0 ? list.get(0) : null;
   
   取下一条
   sql = " from News n where n.id > ? order by n.id asc ";
   List list = getSession().createQuery(sql);
   return list.size > 0 ? list.get(0) : null;

你可能感兴趣的:(sql)