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();