首页 > 代码库 > Hibernate 分页
Hibernate 分页
public EmailBean[] findByPage(Date begin, Date end, String emailreference, int pageNo, final int pageSize, String status) throws AIException { List emails = new ArrayList(); try { Session s = getSessionFactory().getCurrentSession(); Criteria hcriteria = s.createCriteria(EmailBean.class); if (begin != null && end != null) { hcriteria.add(Restrictions.between("creation", begin, end)); } if (emailreference != null && !emailreference.isEmpty()) { hcriteria.add(Restrictions.ilike("mailName", emailreference)); } if (status != null && !status.isEmpty()) { hcriteria.createAlias("status", "s"); hcriteria.add(Restrictions.eq("s.statusname", status)); } //Total record number int totalCount = ((Integer) hcriteria.setProjection(Projections.rowCount()).uniqueResult()).intValue(); hcriteria.setProjection( null ); hcriteria.addOrder(Order.desc("creation")).setFirstResult((pageNo - 1)*pageSize).setMaxResults(pageSize); emails = hcriteria.list(); Hibernate.initialize(emails); } catch (Exception e) { _logger.error(e.fillInStackTrace()); throw new AIException("Error when retrieving emails"); } return emails.toArray(new EmailBean[emails.size()]); }
Hibernate 分页
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。