Skip to content

Instantly share code, notes, and snippets.

@ugandapinik
Last active August 13, 2022 01:38
Show Gist options
  • Save ugandapinik/ece090a930d06b46fbf2832448d308b2 to your computer and use it in GitHub Desktop.
Save ugandapinik/ece090a930d06b46fbf2832448d308b2 to your computer and use it in GitHub Desktop.
Custom findStudentByEmail function will fetch student information using student email address.
/* FIND SOMEONE WITH GIVEN EMAIL ADDRESS
* ==========================================================================*/
studentRepository
.findStudentByEmail("ahmed.ali@gmail.com")
.ifPresentOrElse(
System.out::println,
()-> System.out.println("Student with email ahmed.ali@gmail.com not found"));
public interface StudentRepository extends JpaRepository<Student, Long> {
Optional<Student> findStudentByEmail(String email);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment