文章目录 Hibernate JPA Hibernate JPA CrudRepository的源码 里面有一个函数: /** * Returns the number of entities available. * * @return the number of entities */ long count(); 于是继承了CrudRepository : spring data jpa中使用count计数方法很简单,直接在dao层写方法即可: 例如: Long countByUserId(Long userId);