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 分页的更多相关文章
- Hibernate分页功能数据重复问题
今天遇到一个很憋屈的问题那就是hibernate分页查询中出现重复数据,本来一直没有在意,以为是数据问题,但是一查程序和数据都没有问题,继续深入查看,找到问题了就是order By 时出的问题,唉.. ...
- Hibernate分页查询小结
通常使用的Hibernate通常是三种:hql查询,QBC查询和QBE查询: 1.QBE(Qurey By Example)检索方式 QBE 是最简单的,但是功能也是最弱的,QBE的功能不是特别强大, ...
- hibernate分页模糊查询
在web项目中,显示数据一般采用分页显示的,在分页的同时,用户可能还有搜索的需求,也就是模糊查询,所以,我们要在dao写一个可以分页并且可以动态加条件查询的方法.分页比较简单,采用hibernate提 ...
- Hibernate 分页 查询
昨天的作业 分页: 主要的代码块:(明天实现分页的封装) package com.cy.beans; import java.util.List; /** * 定义一个分页对象 * @author ...
- struts2+hibernate(分页实现)
//Dao类中实现了list集合和pagetotal方法 package zjf.strhib.Dao; import java.util.ArrayList; import java.util.Li ...
- Hibernate分页查询的两个方法
Hibernate中HQL查询语句有一个分页查询, session.setMaxResult(参数)和session.setFirstResult(参数) 如果只设置session.setMaxRes ...
- hibernate -- 分页模糊查询中setParameter 和setParameterList
在分页模糊查询中碰到setParameter 和setParameterList这两个方法 setParameter 以前就只会用setParameter(int arg,String str),我用 ...
- Hibernate 分页时 Long 无法转化成Integer类型 异常
转自:http://loquat.iteye.com/blog/818547 报错:java.lang.Long cannot be cast to java.lang.Integer Long ...
- hibernate分页实现
1.创建分页实体类 public class PageBean { private int page; // 页码 private int rows; // 每页显示行数 private int st ...
- Java项目中基于Hibernate分页总结
1,First of all, we should have a wrapper class for page,this class can calculate the startRow by th ...
随机推荐
- VS与Windbg调试
原文 : https://blog.csdn.net/fin86889003/article/details/20126593 原文 : https://blog.csdn.net/u014339 ...
- python全局解释器GIL
1.什么是进程: 进程是竞争计算机资源的基本单位.对于单核CPU来讲,同一时间只能有一个进程在运行,所以当我们开启多个应用时,操作系统需要根据进程调度算法去在不同的应用程序之间切换,而不同的进程之间切 ...
- On the structure of submodule of finitely generated module over PID
I was absorbed into this problem for three whole days......
- 软工+C(4): Alpha/Beta换人
// 上一篇:超链接 // 下一篇:工具和结构化 注:在一次软件工程讨论课程进度设计的过程中,出现了这个关于 Alpha/Beta换人机制的讨论,这个机制在不同学校有不同的实施,本篇积累各方观点,持续 ...
- python3中的 zip()函数 和python2中的 zip()函数 的区别
python3中的 zip()函数 和python2中的 zip()函数 的区别: 描述: zip() 函数用于将可迭代对象作为参数,将对象中对应的元素打包成一个个元组,然后返回由这些元组组成的对象. ...
- 代理与hook
参考:Java 动态代理 代理是什么 为什么需要代理呢?其实这个代理与日常生活中的“代理”,“中介”差不多:比如你想海淘买东西,总不可能亲自飞到国外去购物吧,这时候我们使用第三方海淘服务比如惠惠购物助 ...
- python读取导出数据
1,python读取csv的某一列 import pandas as pd data1 = pd.read_csv('cotton.csv', usecols=[0, 1], encoding='ut ...
- Luogu4491 [HAOI2018]染色 【容斥原理】【NTT】
题目分析: 一开始以为是直接用指数型生成函数,后来发现复杂度不对,想了一下容斥的方法. 对于有$i$种颜色恰好出现$s$次的情况,利用容斥原理得到方案数为 $$\binom{m}{i}\frac{P_ ...
- 常见的概率分布类型(Probability Distribution)
统计学中最常见的几种概率分布分别是正态分布(normal distribution),t分布(t distribution),F分布(F distribution)和卡方分布(χ2 distribut ...
- git学习02 - log查看&版本回退
1.查看更新记录 git log / git log --pretty=oneline D:\learn\git_test>git log commit a915e7b12076673d778 ...