一般写法:
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 }