sql查询怎么改成hql呀?
取下一条selectmax(id)fromnewswhereid<"+id+"orderbyiddesclimit0,1;...
取下一条
select max(id) from news where id< "+id+" order by id desc limit 0,1; 展开
select max(id) from news where id< "+id+" order by id desc limit 0,1; 展开
1个回答
展开全部
//一下帮您提供一个分页的方法
public static void page()
{
Session s = null;
try
{
s = HibernateUtil.getSeesion();
final String hql = " from news "; //news是你的类名
final Query q = s.createQuery(hql);
q.setFirstResult(0); //从第0条开始
q.setMaxResults(10); //取出10条
final List list = q.list();
for (final User u : list)
{
System.out.println(u.getId() + " " + u.getName());
}
}
finally
{
s.clear();
}
}
public static void page()
{
Session s = null;
try
{
s = HibernateUtil.getSeesion();
final String hql = " from news "; //news是你的类名
final Query q = s.createQuery(hql);
q.setFirstResult(0); //从第0条开始
q.setMaxResults(10); //取出10条
final List list = q.list();
for (final User u : list)
{
System.out.println(u.getId() + " " + u.getName());
}
}
finally
{
s.clear();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询