QueryDsl 생성 및 사용

HelloWorld·2022년 10월 3일
0

Springboot-fruitable

목록 보기
1/1

QueryDsl

build.gradle

(querydsl 관련 부분만 남겨둠)

buildscript {
	ext {
		queryDslVersion = "5.0.0"
	}
}

plugins {
	...
	id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10'
}

...

dependencies {
	...

	implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
	implementation "com.querydsl:querydsl-apt:${queryDslVersion}"

	annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
}

def querydslDir = "$buildDir/generated/querydsl"

querydsl {
	jpa = true
	querydslSourcesDir = querydslDir
}

sourceSets {
	main.java.srcDir querydslDir
}

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
	querydsl.extendsFrom compileClasspath
}

compileQuerydsl {
	options.annotationProcessorPath = configurations.querydsl
}
...

Q클래스 생성


1. Gradle 탭을 들어간다
2. Tasks->other->compileQuerydsl
3. Run


Q클래스 생성!

Examples

JPA

QCustomer customer = QCustomer.customer;
JPAQuery<?> query = new JPAQuery<Void>(entityManager);
Customer bob = query.select(customer)
  .from(customer)
  .where(customer.firstName.eq("Bob"))
  .fetchOne();

Querydsl
QueryDSL 완벽 이해하기

0개의 댓글