Search code examples
javaspringspring-bootjpaspring-data

is there any function in jpa to find customer by its firstName


I want to fetch the record from the database by using JPA base in built query I want to fetch the customer by its first Name so is there any method like below example available?

Customer findByfirst-name(String name); // I tried it

but not found the best solutions I want to get the response as per FirstName of Customer


Solution

  • You may define a method in your repository interface with a particular naming convention to find a customer by their first name using Spring Data JPA. Here's an example of how to do this, assuming you have an entity class named Customer with a field called firstName:

    Customer findByFirstName(String firstName);