/* select member1 from Member member1 where member1.username = ?1 and member1.age = ?2 */ select member0_.member_id as member_i1_1_, member0_.age as age2_1_, member0_.team_id as team_id4_1_, member0_.username as username3_1_ from member member0_ where member0_.username=? and member0_.age=?
List<Member> result = searchMember2(usernameParam, ageParam); assertThat(result.size()).isEqualTo(1); }
private List<Member> searchMember2(String usernameCond, Integer ageCond) { return queryFactory .selectFrom(member) // where 에 null 값이 전달 되면 조건을 무시한다. .where(usernameEq(usernameCond), ageEq(ageCond)) .fetch(); }
private Predicate usernameEq(String usernameCond) { // 전달받은 usernameCond 파라미터가 없을 경우 null 을 반환하도록 한다. if (usernameCond == null) { returnnull; } return member.username.eq(usernameCond); }