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 分页的更多相关文章

  1. Hibernate分页功能数据重复问题

    今天遇到一个很憋屈的问题那就是hibernate分页查询中出现重复数据,本来一直没有在意,以为是数据问题,但是一查程序和数据都没有问题,继续深入查看,找到问题了就是order By 时出的问题,唉.. ...

  2. Hibernate分页查询小结

    通常使用的Hibernate通常是三种:hql查询,QBC查询和QBE查询: 1.QBE(Qurey By Example)检索方式 QBE 是最简单的,但是功能也是最弱的,QBE的功能不是特别强大, ...

  3. hibernate分页模糊查询

    在web项目中,显示数据一般采用分页显示的,在分页的同时,用户可能还有搜索的需求,也就是模糊查询,所以,我们要在dao写一个可以分页并且可以动态加条件查询的方法.分页比较简单,采用hibernate提 ...

  4. Hibernate 分页 查询

    昨天的作业  分页: 主要的代码块:(明天实现分页的封装) package com.cy.beans; import java.util.List; /** * 定义一个分页对象 * @author ...

  5. struts2+hibernate(分页实现)

    //Dao类中实现了list集合和pagetotal方法 package zjf.strhib.Dao; import java.util.ArrayList; import java.util.Li ...

  6. Hibernate分页查询的两个方法

    Hibernate中HQL查询语句有一个分页查询, session.setMaxResult(参数)和session.setFirstResult(参数) 如果只设置session.setMaxRes ...

  7. hibernate -- 分页模糊查询中setParameter 和setParameterList

    在分页模糊查询中碰到setParameter 和setParameterList这两个方法 setParameter 以前就只会用setParameter(int arg,String str),我用 ...

  8. Hibernate 分页时 Long 无法转化成Integer类型 异常

    转自:http://loquat.iteye.com/blog/818547 报错:java.lang.Long cannot be cast to java.lang.Integer   Long ...

  9. hibernate分页实现

    1.创建分页实体类 public class PageBean { private int page; // 页码 private int rows; // 每页显示行数 private int st ...

  10. Java项目中基于Hibernate分页总结

    1,First of all,  we should have a wrapper class for page,this class can calculate the startRow by th ...

随机推荐

  1. Windows 2008 R2 域控制器迁移至windows 2016记录

    文章参考 https://social.technet.microsoft.com/Forums/zh-CN/21a5f5e9-feee-4454-acad-fd22989d7bed/22495296 ...

  2. Java 8 Stream介绍及使用2

    (原) stream中另一些比较常用的方法. 1. public static<T> Stream<T> generate(Supplier<T> s) 通过gen ...

  3. 在vultr安装和使用golang

    1.vultr可以用微信或支付宝充值,方便.好像推荐别人用还能挣美分,懒得弄了,参加了一个充10刀送50刀的活动,感觉实惠(实际用时感觉有点小贵). 2.注册登录后,控制面板上billing可查看余额 ...

  4. UVA - 11090 - Going in Cycle!!(二分+差分约束系统)

    Problem  UVA - 11090 - Going in Cycle!! Time Limit: 3000 mSec Problem Description You are given a we ...

  5. redis5.0.4多实例安装

    一.安装第一个实例 https://www.cnblogs.com/qq931399960/p/10584877.html 二.拷贝配置文件 cp /etc/redis.conf /etc/redis ...

  6. DOM中获取宽高、位置总结

    原生JS 一.文档.窗口的宽高和位置 // 获取屏幕的宽高 window.screen.height | window.screen.width // 屏幕可用工作区宽高 window.screen. ...

  7. django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. Did you install mysqlclient or MySQL-python?

    Error msg: Unhandled exception in thread started by <function check_errors.<locals>.wrapper ...

  8. C语言函数及变量的声明与定义的区别

    变量: 1.声明变量不需要建立存储空间,如:extern int a; 2.定义变量需要建立存储空间,如:int a:或者 int b=10:无论变量是否赋值,只要定义它,即占用空间. 3.int a ...

  9. 开发中,IDEA常用的快捷键

    Settings文件: Ctrl+Alt+S 搜索文件:Ctrl+Shift+N 全文搜索: Ctrl+Shift+F 全文替换: Ctrl+Shift+R 搜索内容: Ctrl+F 内容替换: Ct ...

  10. Angular 基本内置服务和筛选器

    AngularJS中的内置服务(共30多个): $http 发送http请求,主要用于进行异步数据请求的功能实现,这个服务主要封装了XMLHttpRequest对象和JSONP数据访问模式来完成远程请 ...