EntityManager entityManager;
CriteriaBuilder criteriaBuilder =entityManager.getCriteriaBuilder();
CriteriaQuerycritQuery = 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(); 实体类>