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

Hibernate的Criteria 之条件查询

程序员文章站 2022-07-12 10:49:23
...
Restrictions用法
hibernate Restrictions用法

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();

	}