@Test
public void startJPQL() {
String qlString = "select m from Member m " +
"where m.username = :username";
Member result = em.createQuery(qlString, Member.class)
.setParameter("username", "member1")
.getSingleResult();
assertThat(result.getUsername()).isEqualTo("member1");
}
@Test
public void startQuerydsl() {
JPAQueryFactory jpaQueryFactory = new JPAQueryFactory(em);
QMember qMember = new QMember("m"); //alias 지정
Member findMember = jpaQueryFactory
.select(qMember)
.from(qMember)
.where(qMember.username.eq("member1"))
.fetchOne();
assertThat(findMember.getUsername()).isEqualTo("member1");
}
쿼리 짜듯이 where 조건에 직접 적용 가능
JPAQueryFactory는 Querydsl 라이브러리에서 제공하는 클래스로, Java Persistence API (JPA) 엔티티를 대상으로 타입 안전한 쿼리를 생성하는 데 사용된다.
도움이 되었습니다.!! :)