spring boot) find 사용하기

박우영·2023년 3월 23일
0

자바/코틀린/스프링

목록 보기
15/35

test 를 하거나 검색을 하는등 다양하게 사용할 수 있는 find가 있다.

기본적으론 findAll, findById와 같은 메서드드를 제공하지만

인터페이스 레포지토리를 통해 간단하게 만들 수 있다.

public interface QuestionRepository extends JpaRepository<Question, Long> {
    Question findBySubject(String subject);
    Question findBySubjectAndContent(String subject, String content);
}

이제 하나의 객체를 생성해서 해당 메서드를 사용해서 조회할 수 있다.

  • DI에 의해 스프링이 자동으로 QuestionRepository 객체를 생성한다. 이 때 프록시 패턴이 사용된다고 한다.

관련 간단한 표 이다.
출처- https://wikidocs.net/160890

0개의 댓글