冰上行舟 2017-02-13 07:50 采纳率: 85.7%
浏览 1128

Hibernate 转换含按规定字段相除后排列及含limit的SQL语句问题,它的dao如何写?

Hibernate 上如何实现这句sql语句:"SELECT * FROM food WHERE isdel = '0' ORDER BY (totalgrade/reviewsnum) DESC LIMIT 5;"

主要想问:它的Dao层应该如何写?

  • 写回答

3条回答 默认 最新

  • Z. ZHANG 2017-02-13 08:33
    关注

    给你个例子

     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;
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题