๋ชฉ์ฐจ

JPA๋ฅผ ์ฌ์ฉํ ๋ ๋์ ๋ฐ ๋ณต์กํ ์ฟผ๋ฆฌ ์์ฑ ์ querydsl์ ์ ํ์ด ์๋ ํ์์ธ๋ฐ ์ด๊ฒ ์ธํ ํ๊ธฐ๊ฐ ์ข ๊น๋ค๋ก์
๊ทธ๋์ ์ด ๊ณณ์ ๋ด๊ฐ ๋์ค์ ๋ณด๊ธฐ์ํด ๋ฉ๋ชจ๋ฅผ ํด๋
์ฒ์ ํ๋ฒ๋ง ํด๋๋ฉด ๋์ค์ ๋ณต๋ถ/์์ ํด์ ์ฌ์ฉํ๋ฉด ๋จ
์ด ๊ธ์์๋ querydsl ๊ธฐ๋ณธ ์ธํ ๋ฐฉ๋ฒ๋ง ๋ค๋ฃธ
mybatis์ ๋น๊ตํด์ ๊ฐ์ธ์ ์ผ๋ก ์ ์ผ ์ข์ ์ ์ mybatis๋ ๋ฐํ์ ๋ ํด๋น ์ฟผ๋ฆฌ๋ฅผ ๋๋ ค๋ด์ผ์ง๋ง ์๋ฌ๋ฅผ ์ ์ ์์ง๋ง querydsl์ ์๋ฐ์ฝ๋๋ผ์ ์คํ์๊ฐ ๋ฌธ๋ฒ ์๋ฌ๊ฐ ์์ผ๋ฉด ์ปดํ์ผ๋จ๊ณ์์ ๋ฐ๋ก ์ ์ ์๋ค.
querydsl ์ธํ ๋ฐฉ๋ฒ ๐
build.gradle ์ค์ ๐
// ์คํ๋ง๋ถํธ 2.6x ๋ฒ์ ์์ ์ธํ
ํจ
buildscript {
ext {
queryDslVersion = "5.0.0"
}
}
plugins {
id 'org.springframework.boot' version '2.6.12'
id 'io.spring.dependency-management' version '1.0.14.RELEASE'
//querydsl ์ถ๊ฐ
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
id 'java'
}
group = 'study'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
//querydsl ์ถ๊ฐ
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.8'
annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}"
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
//ํ
์คํธ์์ lombok ์ฌ์ฉ
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
//querydsl ์ถ๊ฐ ์์
def querydslDir = "$buildDir/generated/querydsl"
querydsl {
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir querydslDir
}
configurations {
querydsl.extendsFrom compileClasspath
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
//querydsl ์ถ๊ฐ ๋
tasks.named('test') {
useJUnitPlatform()
}
complieQuerydsl ๐
build.gradle์ ์ค์ ์ถ๊ฐ ํ ์ธํ ๋ฆฌ์ ์ด ๊ธฐ์ค์ผ๋ก ํ๋จ์ ์ด๋ฏธ์ง์ฒ๋ผ ์ฐ์ธก Gradle์ compileQuerydsl ์ ํํด์ ์ปดํ์ผ ์คํ


๋น๋ ์ฑ๊ณต ์ ์๋์ฒ๋ผ build.gradle์์ ์ค์ ํด ๋์ ๋น๋ ๋๋ ํ ๋ฆฌ์ Q๋ก ์์ํ๋ ํ์ผ์ด ์์ฑ๋์ด ์๋ค.

querydsl์์ ์ฌ์ฉํ๋๊ฒ ์ด Qํ์ผ์ด๋ค.

์ด์ querydsl์ ์ฌ์ฉํ ์ค๋น๋ ๋ค ๋์๋ค.
์ฌ์ฉ๋ฒ์ ์๋์ ๊ฐ์ด querydsl์ ์ฌ์ฉํ ํด๋์ค์ ์์ฑ์์์ EntityManager๋ฅผ ์ฃผ์ ๋ฐ์ JPAQueryFactory๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด ์ฌ์ฉ, ์์ธํ ๋ฌธ๋ฒ์ ์ฐจ์ฐจ ์ฌ๋ฆด ์์ ์(์์ง ์ ๋๋ก ์์ง๊ฐ ๋๊ฒ ์๋๋ผ..)
์ฌ์ฉํ๋ ๋ฐฉ์์ ๊ฐ๋ฐ์๋ง๋ค ์ทจํฅ์ ๋ฐ๋ผ ๋ค์ํจ
์ฌ์ฉ ๋ฌธ๋ฒ์ SQL๊ณผ ๋น์ทํ๊ฒ ๋์ด ์๋ค.(SELECT FROM...)

JPAQueryFactory ์์ค๋ฅผ ๋ณด๋ฉด ์๋์ฒ๋ผ EntityManager๋ฅผ parameter๋ก ๋ฐ๋๊ฒ ๋ณด์ธ๋ค.


'IT > development' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [mybatis] mybatis ์ด์ค foreach insert(feat. ์ด์ค ๊ณ์ธต ๊ฐ์ฒด ์ ์ฅ) (0) | 2022.11.21 |
|---|---|
| [Spring data JPA] ์ด๊ฐ๋จ CRUD (0) | 2022.11.21 |
| [mybatis] mybatis ๋ฐฐ์ด ์ ์ฅ(feat. foreach) (0) | 2022.11.21 |
| [mybatis] mybatis ๋์ ์ฟผ๋ฆฌ(feat. <where></where>) (0) | 2022.11.20 |
| [mybatis] foreach parameterType hashmap ์์ (54) | 2022.11.20 |
๋๊ธ