🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 全查 ~~~ //类SQL语句,不是真的SQL语句 Query qr = entityManager.createQuery("from Customer"); List<Customer> list = qr.getResultList(); System.out.println(list); ~~~ ## 条件查 占位符从1开始的,hibernate是从0开始的: ~~~ //类SQL语句,不是真的SQL语句 Query qr = entityManager.createQuery("from Customer where cust_name like ?"); qr.setParameter(1, "%侠%"); List<Customer> list = qr.getResultList(); System.out.println(list); ~~~ ## 分页查 ~~~ Query qr = entityManager.createQuery("from Customer"); qr.setFirstResult(2); qr.setMaxResults(3); List<Customer> list = qr.getResultList(); for (Customer c : list) { System.out.println(c); } ~~~ ## 聚合查询 ~~~ Query qr = entityManager.createQuery("select count(*) from Customer"); Object singleResult = qr.getSingleResult(); System.out.println(singleResult); ~~~