欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Hibernate的Criteria 之条件查询

程序员文章站 2022-05-23 09:19:46
...
[url=http://www.cnblogs.com/evon168/archive/2010/10/29/1863059.html]Restrictions用法[/url]
[url=http://xuganggogo.iteye.com/blog/440078]hibernate Restrictions用法[/url]

Criteria获取记录总数示例代码:
	@Override
public Long getCount(Map<String, Object> param) throws ParseException {

Date upload_time_s = DateUtils.parseDate(param.get("upload_time_s").toString(), "yyyy-MM-dd HH:mm:ss");
Date upload_time_e = DateUtils.parseDate(param.get("upload_time_e").toString(), "yyyy-MM-dd HH:mm:ss");

Criteria criteria = getSession().createCriteria(TransmitErrorRecord.class);
criteria.add(Restrictions.ge("uploadTime", upload_time_s));
criteria.add(Restrictions.le("uploadTime", upload_time_e));

criteria.setProjection(Projections.rowCount());

return (Long) criteria.uniqueResult();

}