hibernate中的分页处理

更新时间 🔔🕙 2021年5月4日

引用地址: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();
	}

转载请备注引用地址:编程记忆 » hibernate中的分页处理