Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- ์คํํ๋ ๋ฏธ์ค
- Codedeploy ์ค๋ฅ
- docker compose
- s3 ์ด๋ฏธ์ง ๋ค์ด๋ก๋
- redis ์กฐํ
- ์ ํจ์ค ๋น๋ ์ค๋ฅ
- nGrinder
- docker-compose kafka
- docker
- ํ๋ก๊ทธ๋๋จธ์ค
- ์ ํจ์ค ์ค์ผ์ค๋ฌ
- s3 log ์ ์ฅ
- private subnet ec2 ๋ก์ปฌ ์ ์
- @RestControllerAdvice
- ์๋ฐ
- ๋ค์ค ์ปจํ ์ด๋
- s3 ์ด๋ฏธ์ง ์ ์ฅ
- aws saa ํฉ๊ฒฉ
- aws ์ฟ ํฐ
- docker ps -a
- prod docker-compose
- ์๋ฒ ํฐ์ง๋ ๋์ปค ์ฌ์คํ
- ํ๋ก๊ทธ๋๋จธ์ค ์ปฌ๋ฌ๋ง๋ถ
- JPA
- ํ์ดํผ๋ฐ์ด์
- ํ๋ก๊ทธ๋๋จธ์ค ํฉ์นํ์์๊ธ
- Kafka
- AWS Certified Solutions Architect - Associate
- Entity
- redis ํ ์คํธ์ฝ๋
Archives
- Today
- Total
๐๐ข๐๐ โ๐๐๐ ๐๐๐ก๐๐ ๐๐๐๐โง
[Spring] QueryDSL ๋ณธ๋ฌธ
๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ด๐ป/๐๐ฉ๐ซ๐ข๐ง๐
[Spring] QueryDSL
๐คRyusun๐ค 2023. 7. 18. 16:26QueryDSL
- ์ ์ ํ์ ์ ์ด์ฉํด SQL๊ณผ ๊ฐ์ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํ ์ ์๋๋ก ์ง์ํ๋ ํ๋ ์์ํฌ
- ์ฟผ๋ฆฌ๋ฅผ ๋ฌธ์๊ฐ ์๋ ์ฝ๋๋ก ์์ฑํด๋, ์ฝ๊ณ ๊ฐ๊ฒฐํ๋ฉฐ ๊ทธ ๋ชจ์๋ ์ฟผ๋ฆฌ์ ๋น์ทํ๊ฒ ๊ฐ๋ฐํ ์ ์๋ ์คํ์์ค ํ๋ก์ ํธ
QueryDSL์ ์ฅ์
- IDE๊ฐ ์ ๊ณตํ๋ ์ฝ๋ ์๋ ์์ฑ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์๋ค.
- ๋ฌธ๋ฒ์ ์ผ๋ก ์๋ชป๋ ์ฟผ๋ฆฌ๋ฅผ ํ์ฉํ์ง ์๋๋ค. ๋ฐ๋ผ์ ์ ์์ ์ผ๋ก ํ์ฉ๋ QueryDSL์ ๋ฌธ๋ฒ ์ค๋ฅ๋ฅผ ๋ฐ์์ํค์ง ์๋๋ค.
- ๊ณ ์ ๋ SQL ์ฟผ๋ฆฌ๋ฅผ ์์ฑํ์ง ์๊ธฐ ๋๋ฌธ์ ๋์ ์ผ๋ก ์ฟผ๋ฆฌ๋ฅผ ์์ฑํ ์ ์๋ค.
- ์ฝ๋๋ก ์์ฑํ๋ฏ๋ก ๊ฐ๋ ์ฑ ๋ฐ ์์ฐ์ฑ์ด ํฅ์๋๋ค.
- ๋๋ฉ์ธ ํ์ ๊ณผ ํ๋กํผํฐ๋ฅผ ์์ ํ๊ฒ ์ฐธ์กฐํ ์ ์๋ค.
QueryDSL ์ค์
buildscript {
ext {
queryDslVersion = "5.0.0"
}
}
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.13'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
//querydsl ์ถ๊ฐ
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '11'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
//querydsl ์ถ๊ฐ
//querydsl ์ถ๊ฐ
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}"
}
tasks.named('test') {
useJUnitPlatform()
}
//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 ์ถ๊ฐ ๋
ํ๊ฒฝ ์ค์ ์ ์๋ฃํ์ผ๋ฉด Gradle -> Tasks -> other -> compileQuerydsGradle๋ฅผ ๋๋ฌ Qํ์ ์ ์์ฑํด์ค๋ค.
Q ํ์ ์์ฑ๋๋์ง ํ์ธํ ๋ ค๋ฉด build -> generated -> querydsl -> example.querydsl.entity.QHello.java ํ์ผ์ด ์์ฑ๋์ด ์์ด์ผ ํ๋ค.
package com.example.querydsl.entity;
import static com.querydsl.core.types.PathMetadataFactory.*;
import com.querydsl.core.types.dsl.*;
import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;
/**
* QHello is a Querydsl query type for Hello
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QHello extends EntityPathBase<Hello> {
private static final long serialVersionUID = -932168945L;
public static final QHello hello = new QHello("hello");
public final NumberPath<Long> id = createNumber("id", Long.class);
public QHello(String variable) {
super(Hello.class, forVariable(variable));
}
public QHello(Path<? extends Hello> path) {
super(path.getType(), path.getMetadata());
}
public QHello(PathMetadata metadata) {
super(Hello.class, metadata);
}
}
ํ ์คํธ ์ผ์ด์ค๋ก ์คํ ๊ฒ์ฆ
package com.example.querydsl;
import com.example.querydsl.entity.Hello;
import com.example.querydsl.entity.QHello;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
@Transactional
class QuerydslApplicationTests {
@Autowired
EntityManager em;
@Test
void contextLoads() {
Hello hello = new Hello();
em.persist(hello);
JPAQueryFactory query = new JPAQueryFactory(em);
QHello qHello = new QHello("h");
Hello result = query
.selectFrom(qHello)
.fetchOne();
// ctrl + alt + v
assertThat(result).isEqualTo(hello);
Assertions.assertThat(result.getId()).isEqualTo(hello.getId());
}
}
ํ ์คํธ ํต๊ณผ
'๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ด๐ป > ๐๐ฉ๐ซ๐ข๐ง๐ ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JPA] @Enumerated, @Converter (0) | 2023.08.26 |
---|---|
[Spring] QueryDSL ๋ฌธ๋ฒ (0) | 2023.07.20 |
[Spring] ์์ธ ์ฒ๋ฆฌ (0) | 2023.06.30 |
[Spring] RestTemplate, UriComponentsBuilder (0) | 2023.06.28 |
[Spring Batch] JobInstance, JobParameter, JobExecution, JobScope (0) | 2023.06.23 |