Hibernate 上如何实现这句sql语句:"SELECT * FROM food WHERE isdel = '0' ORDER BY (totalgrade/reviewsnum) DESC LIMIT 5;"
主要想问:它的Dao层应该如何写?
Hibernate 上如何实现这句sql语句:"SELECT * FROM food WHERE isdel = '0' ORDER BY (totalgrade/reviewsnum) DESC LIMIT 5;"
主要想问:它的Dao层应该如何写?
给你个例子
public List<Idcard> queryByName(int idcardCode) throws Exception {
List<Idcard> list = new ArrayList<Idcard>();
list = null;
try {
session = sessionFactory.getCurrentSession();
String hql = "from Idcard idcard where idcard.idcardCode=?";
Query q = session.createQuery(hql);
q.setParameter(0, idcardCode);
list = q.list();
} catch (Exception e) {
System.out.print("数据查询失败!");
e.printStackTrace();
}
return list;
}