public EmailBean[] findByPage(Date begin, Date end, String emailreference, int pageNo, final int pageSize, String status) throws AIException {
List<EmailBean> emails = new ArrayList<EmailBean>();
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 分页,查找总记录数
最新推荐文章于 2024-11-03 10:06:51 发布