728x90
728x90
Repository Custom
-
[Spring] JPA Repository 커스텀하기 - Repository 분리, 쿼리 방식 다르게 등에 사용JAVA/Spring(Springboot) 2023. 4. 4. 10:58
JPA Repository 한 파일에 메서드를 정의하게 되면 중요한 핵심 로직과 단순한 조회 로직 등 여러 메서드가 섞여서 저장되기 때문에 유지보수하기에 어려운 점이 있다. 또한 한 Repository 안에서 Spring data jpa 를 사용할 수도 있고 기본 myBatis를 사용할 수도 있고, jdbc template를 사용할 수도 있다면 Repository 분리가 필요하게 된다. Repository 는 하나로 사용하되, custom된 interface를 상속받으면 된다. 코드로 살펴보자. 아래를 보면 MemberRepository 에 여러 메서드가 조회되어 있다. public interface MemberRepository extends JpaRepository { List findUser(Str..