In JPA 2, using a CriteriaQuery, how to count results

前端 未结 7 1173
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 19:28

I am rather new to JPA 2 and it\'s CriteriaBuilder / CriteriaQuery API:

CriteriaQuery javadoc

CriteriaQuery in the Java EE 6 tutorial

I would like to

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 20:09

    With Spring Data Jpa, we can use this method:

        /*
         * (non-Javadoc)
         * @see org.springframework.data.jpa.repository.JpaSpecificationExecutor#count(org.springframework.data.jpa.domain.Specification)
         */
        @Override
        public long count(@Nullable Specification spec) {
            return executeCountQuery(getCountQuery(spec, getDomainClass()));
        }
    

提交回复
热议问题