Does Spring Data JPA have any way to count entites using method name resolving?

后端 未结 12 936
耶瑟儿~
耶瑟儿~ 2020-12-04 08:38

Spring Data JPA supports counting entities using specifications. But does it have any way to count entities using method name resolving? Let\'s say I want a method cou

12条回答
  •  感动是毒
    2020-12-04 09:13

    Working example

    @Repository
    public interface TenantRepository extends JpaRepository< Tenant, Long > {
        ListfindByTenantName(String tenantName,Pageable pageRequest);
        long countByTenantName(String tenantName);
    }
    

    Calling from DAO layer

    @Override
    public long countByTenantName(String tenantName) {
        return repository.countByTenantName(tenantName);
    }
    

提交回复
热议问题