HQL分页查询

转自:https://blog.csdn.net/dwenxue/article/details/80460161

【例】雇员信息


分页查询
(1)setFirstResult(int firstResult):设置开始检索的对象。

(2)setMaxResults(int maxResults):设置每次检索返回的最大对象数。

session=HibernateSessionFactory.getSession();
String hql="from Employee";
Query query=session.createQuery(hql);
query.setFirstResult(0);
query.setMaxResults(3);
List<Employee>list=query.list();
for(Employee emp:list){
System.out.println(emp.getEmp_id()+" "+emp.getEmp_name()+" "+emp.getEmp_sex()+
" "+emp.getEmp_birth()+" "+emp.getEmp_job()+" "+emp.getEmp_salary());
}
运行结果:


---------------------
作者:云淡风轻58
来源:CSDN
原文:https://blog.csdn.net/dwenxue/article/details/80460161?utm_source=copy
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/sharpest/p/9789970.html