Spring Data JPA - finding number of rows from the database

10,640

There is method count() in CrudRepository. You can check oficial documentation.

Share:
10,640

Related videos on Youtube

Matt-pow
Author by

Matt-pow

Updated on June 04, 2022

Comments

  • Matt-pow
    Matt-pow almost 2 years

    I am a noob in Spring framework. I know there is the findAll method to query all the data in a database. Is there a way to count the number of rows in a database using the Spring framework and doesn't require to write a SQL query?

  • aswzen
    aswzen over 3 years
    how to add condition to that count
  • Woodchuck
    Woodchuck over 2 years
    You could just add something like this to your repository: long countBySomeField(String someField);