引用地址:http://blog.knowsky.com/255646.htm
hibernate中的分页与sql语句的分页有点差异。
mysql中的分页语句:
select * from table limit 开始索引,查询数量;
hibernate中不能直接这样写hql,需要修改为:
public List<user> getUserById(final int userId, final int maxCount, final int firstResult) throws Exception {
String hql = "from User where userId=? ";
Query query = session.createQuery(hql);
query.setParameter(0, userId);
query.setMaxResults(maxCount);
query.setFirstResult(firstResult);
return query.list();
}
沪公网安备 31011502001064号