`
AllenHU0320
  • 浏览: 82944 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Hibernate的VO在HQL语句中的应用

 
阅读更多

HQL语句为:

select new com.xxx.vo.TAdminDefineReportVo(a.defineReportId,a.reportTmpId,

      c.reportName,a.admin,a.reportType,a.description,

      a.status,a.createTime,a.autoSend,a.emails,b.userName)

from TAdminDefineReport a,TReportTemplate c,TAdminInfo b

where a.reportTmpId = c.reportTmpId

and a.admin = b.administrorId

and a.admin = ?  $queryClause$

order by  a.reportTmpId desc,a.createTime desc

 

DaoImpl类:

 public Pagination getAdminRepByAdmId(int admId,String queryName,String reportType,String startTime,String endTime){
  try{
   String hql = this.getHql("repTmp.hql10");
   
   StringBuilder sb = new StringBuilder();
   if(("".equals(queryName)||queryName==null)&&("-1".equals(reportType)||reportType==null)
     &&("".equals(startTime)||startTime==null)&&("".equals(endTime)||endTime==null)){
    hql = hql.replace("$queryClause$", "");
   }
   if(!"".equals(queryName) && queryName != null){
    sb.append(" and b.reportName like '%" + queryName + "%'");
   }
   if(!"-1".equals(reportType)&&!"".equals(reportType)){
    sb.append(" and a.reportType = '" + reportType + "'");
   }
   if(!"".equals(startTime) && startTime != null){
    sb.append(" and a.createTime >= '" + startTime + "'");
   }
   if(!"".equals(endTime) && endTime != null){
    sb.append(" and a.createTime <= '" + endTime + "'");
   }
   hql = hql.replace("$queryClause$", sb.toString());
   
   return this.searchPaginated(hql,admId);
  }catch(Exception e){
   logger.error(e.getMessage());
   throw new PersistenceException(e.getMessage());
  }
 }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics