带选择的sql简单用法

一般写法:

select * from itcast_topic order by (case type when 2 then 2 else 1 end ) desc ,postTime desc

 

hql写法类似:

1 public List<Topic> findTopicByForum(Forum model) {
2         String hql = "FROM Topic t WHERE t.forum = ? ORDER BY (CASE t.type WHEN 2 THEN 2 ELSE 1 END) DESC,t.postTime DESC";
3         Query query = this.getSession().createQuery(hql);
4         query.setParameter(0, model);
5         return query.list();
6     }

 

posted @ 2016-09-12 21:52  懒得像猪  阅读(192)  评论(0编辑  收藏  举报