在HQL+MYSQL中不能直接在查询语句中使用LIMIT进行检索,正确方法为:

String hql = "from User where id=? order by addDate desc";
Query query = session.createQuery(hql);
query.setParameter(0, userId);
query.setFirstResult(pageroffset);
query.setMaxResults(e);
pageroffset:开始检索的位置,int
e:返回最大记录行,int
执行此HQL后在生成的查询语句中会自动加上limit ?。

例:查询前5条数据:

query.setFirstResult(0);
query.setMaxResults(4);

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2021-10-08
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案