Q 타입을 생성하여 사용하는 방법은 2가지가 있다
querydsl은 결국 JPQL의 빌더이다.
Member resultFindMember = jpaQueryFactory
.selectFrom(QMember.member)
.from(QMember.member)
.where(QMember.member.username.eq("member1"))
.fetchOne();
static 임포트 처리
import static study.querydslpractice.entity.QMember.member;
Member resultFindMember = jpaQueryFactory
.selectFrom(member)
.from(member)
.where(member.username.eq("member1"))
.fetchOne();
설정을 추가하면 실행되는 JPQL을 볼 수 있다.
spring:
jpa:
hibernate:
use_sql_comments: true
이때 만약 별칭을 변경하여 사용하고 싶은 경우
m
으로 쿼리가 나오게 된다/* select member1
from Member member1
where member1.username = ?1 */
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 t_member member0_ where member0_.username=?