@Override
public int getCount(PlanSearchCriteria criteria) throws Exception {
StringBuilder hql = new StringBuilder();
hql.append("SELECT COUNT(*) FROM Plan plan ");
Map<String,Object> parameters = new HashMap<String,Object>();
hql.append(" WHERE 1 = 1 ");
if(StringUtils.isNotEmpty(criteria.getPlanStatus())) {
hql.append(" AND plan.planStatus = :planStatus ");
parameters.put("planStatus", PlanStatus.valueOf(criteria.getPlanStatus()));
}
if(StringUtils.isNotEmpty(criteria.getPlanType())) {
hql.append(" AND plan.planType = :planType ");
parameters.put("planType", PlanType.valueOf(criteria.getPlanType()));
}
if(StringUtils.isNotEmpty(criteria.getNoticeTime())) {
hql.append(" AND to_char(plan.notice.noticeTime,'yyyy-MM-dd') = :noticeTime" );
parameters.put("noticeTime", criteria.getNoticeTime());
}
Query query = getSession().createQuery(hql.toString());
return ((Long) setParameter(query,parameters).uniqueResult())
.intValue();
}
private Query setParameter(Query query,Map<String,Object> parameters) {
if(parameters.get("planStatus") != null) {
query.setParameter("planStatus", parameters.get("planStatus"));
}
if(parameters.get("planType") != null) {
query.setParameter("planType", parameters.get("planType"));
}
if(parameters.get("noticeTime") != null) {
query.setParameter("noticeTime", parameters.get("noticeTime"));
}
return query;
}
Hibernate HQL查询中对日期的查询操作总结
最新推荐文章于 2024-05-19 02:40:30 发布