hql语句拼接的替换方式

hql语句拼接的替换方式

hql语句拼接

          String hql = "FROM Topic t WHERE t.forum=?  ";
List<Object> parameters = new ArrayList<Object>();
parameters.add(forum);
if (viewType == 1) {
hql += "AND t.type = ?";
parameters.add(Topic.TYPE_BEST);
}
if(orderBy == 1){ //1表示只按最后更新时间排序
hql += "ORDER BY t.lastUpdateTime " + (asc?"ASC":"DESC");
}else if(orderBy == 2){//2表示只按主题发表时间排序
hql += "ORDER BY t.postTime " + (asc?"ASC":"DESC");
}else if(orderBy == 3){//3表示只按回复数量排序
hql += "ORDER BY t.replyCount " + (asc?"ASC":"DESC");
}else{ //0表示默认排序(置顶帖在前面, 并按最后更新时间降序排序)
hql += "ORDER BY (CASE t.type WHEN 2 THEN 2 ELSE 0 END) DESC, t.lastUpdateTime DESC";
}

  

上一篇:IE中使用ajaxSubmit上传文件弹出下载提示框


下一篇:Hadoop MapReduce编程 API入门系列之Crime数据分析(二十五)(未完)