Skip to content

Instantly share code, notes, and snippets.

@wohhie
Last active August 13, 2022 01:38
Show Gist options
  • Save wohhie/ece090a930d06b46fbf2832448d308b2 to your computer and use it in GitHub Desktop.
Save wohhie/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("[email protected]")
.ifPresentOrElse(
System.out::println,
()-> System.out.println("Student with email [email protected] 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