H3-1. AND 조건 처리 → Method Chaining

@Test // Default Format of Searching Query
public void testDefaultSearch(){
    Slave found = queryFactory
            .selectFrom(slave) // Use Default Instance
            .where(slave.slaveName.eq("slave1").and(slave.age.eq(10))) // Parameter Binding
            .fetchOne();

    assert found != null;
    assertThat(found.getSlaveName()).isEqualTo("slave1");
}

↳ Where 에서 Method Chaining이 가능하다.

↳ select, from → selectFrom 으로 병합 가능

H3-2. AND 조건 처리 → Parameter 👍🏻

@Test // AND Condition with Parameter
public void testSearchAndParam(){
    List<Slave> slaves = queryFactory
            .selectFrom(slave)
            .where(slave.slaveName.eq("slave1"), slave.age.eq(10)) // Multiple Parameters
            .fetch(); // List 출력할 땐 fetch()를 사용한다. (cf. fetchOne()은 단일 결과를 반환할 때 사용)

    assertThat(slaves).hasSize(1); 
}

↳ where() 에 파라미터로 검색조건을 추가 시 AND 조건이 추가된다.

null 값 무시 → 메서드 추출을 통해 동적 쿼리를 깔끔하게 만들 수 있다.