Spring Data JPA - 메소드 이름으로 쿼리 생성하기

목차

메소드 이름으로 쿼리 생성하기

https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation

@Test
public void findByUsernameAndAgeGreaterThen(){
Member member1 = new Member("AAA", 10);
Member member2 = new Member("AAA", 20);
memberJpaRepository.save(member1);
memberJpaRepository.save(member2);

List<Member> result = memberJpaRepository.findByUsernameAndAgeGreaterThan("AAA", 15);

assertThat(result.get(0).getUsername()).isEqualTo("AAA");
assertThat(result.get(0).getAge()).isEqualTo(20);
assertThat(result.size()).isEqualTo(1);
}
List<Member> findByUsernameAndAgeGreaterThan(String username, int age);
Share