Skip to content

Commit

Permalink
[Week9][Chap4] Feat : 리포지토리에 쿼리정의(@query) (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
songhee1 committed Nov 20, 2023
1 parent 8e76dec commit c72a592
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package study.datajpa.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import study.datajpa.entity.Member;

import java.util.List;

public interface MemberRepository extends JpaRepository<Member, Long> {
List<Member> findByUsername(String username);
List<Member> findByUsernameAndAgeGreaterThan(String username, int age);

@Query("select m from Member m where m.username = :username and m.age = :age")
List<Member> findUser(@Param("username") String username, @Param("age") int age);
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,17 @@ public void findByUsernameAndAgeGreaterThan(){
assertThat(result.size()).isEqualTo(1);

}

@Test
public void testQuery(){
Member m1 = new Member("AAA", 10);
Member m2 = new Member("BBB", 20);

memberRepository.save(m1);
memberRepository.save(m2);

List<Member> result = memberRepository.findUser("AAA", 10);
assertThat(result.get(0)).isEqualTo(m1);

}
}

0 comments on commit c72a592

Please sign in to comment.