2007-10-26
分页查询
关键字: 分页查询/**
*
* <p>
* 查询每页的职员及其角色
* <p>
* <p>
* 使用左外连接,HQL语法
*
* @param page
* 表示第几页
* @param maxResult
* 表示每页显示多少条
* @author chenwei
* @since 1.0
* @return java.util.List
* @throws SessionFactoryException
*
*/
public List getEmpAndRole(int page, int maxResult)
throws SessionFactoryException {
Session ses = null;
Transaction tran = null;
List list = null;
try {
ses = SessionFactory.getSession();
tran = ses.beginTransaction();
list = ses.createQuery("from Employee e left join e.role")
.setFirstResult((page - 1) * maxResult).setMaxResults(
maxResult).list();
// setFirstResult(index):从第机个对象开始检索
// setMaxResults(count):每次检索多少个对象
} catch (SessionFactoryException e) {
e.printStackTrace();
SessionFactory.rollBackTransaction(tran);
} finally {
tran.commit();
SessionFactory.closeSession(ses);
}
return list;
}
发表评论
- 浏览: 17517 次
- 性别:

- 来自: 广州

- 详细资料
搜索本博客
我的相册
2008-6-26
共 122 张
共 122 张
最近加入圈子
最新评论
-
创建XMLHttpRequest对象及 ...
返回XML文档 PrintWriter out = null; try ...
-- by weiweichen1985 -
存储过程的创建和调用。。 ...
嵌套循环 CREATE DEFINER=`root`@`localhost` ...
-- by weiweichen1985 -
js实现的年月日三级联动
日历来的更简洁,让用户操作三遍,不符合用户体验。
-- by igogo007 -
js实现的年月日三级联动
谢谢了,代码我收藏了啊
-- by hanhan7673 -
word提示用安全模式打开
...
-- by sunfengcheng






评论排行榜