日期:2014-05-17 浏览次数:20958 次
String hql = "from TbArticle model where 1=1 "; hql += "and model.subject.id = "+subjectId+" "; hql += "and model.type = 2 "; hql += "order by model.createTime desc";
select * from (select * from TbArticle model order by model.createTime desc) where rownum<2
------解决方案--------------------
不可以这样么?
String hql = "select * from (select * from TbArticle model where 1=1 "; hql += "and model.subject.id = "+subjectId+" "; hql += "and model.type = 2 "; hql += "order by model.createTime desc)"; hql += " where rownum<2";
------解决方案--------------------
直接在 HQL 里面加where 判断不行么? 如果用sql查询,也可以,但是返回的是一个对象数组。