spring jpa 条件查询统计

EntityManager entityManager;
CriteriaBuilder criteriaBuilder =entityManager.getCriteriaBuilder();
CriteriaQuery<Entity> critQuery = criteriaBuilder.createQuery(实体类.class);
Root<实体类> root = critQuery.from(实体类.class);
Predicate predicate = criteriaBuilder.equal(root.get(字段).as(Integer.class),"条件参数");
critQuery.where(predicate);
return
entityManager.createQuery(critQuery).getResultList().size();

posted on 2016-06-14 18:04  java疯子  阅读(4032)  评论(0编辑  收藏  举报

导航