
적용이유
filter, category를 통한 검색을 위해 동적 쿼리를 사용하기 위해서 적용 (JPA에서 제공하는 쿼리문에는 한계가 있음을 느꼈다.)
build.gradle -> dependencies{}
// QueryDSL 설정
// == 스프링 부트 3.0 이상 ==
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
// == 스프링 부트 3.0 미만 ==
// implementation 'com.querydsl:querydsl-jpa'
// annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jpa"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
빌드를 다시하고 어플리케이션을 한번 Run을 해줘야 QEntity를 사용할 수 있다. -> 적용이 안됬다고 놀라지 않기...!
BoardInQueryImpl.java
public class BoardInQueryImpl extends QuerydslRepositorySupport implements BoardInQuery {
@PersistenceContext
private EntityManager entityManager;
public BoardInQueryImpl() {
super(Board.class);
}
정리
쿼리가 코드형태로 변경되어 바로 디버그가 가능하며 가독성 향상
BooleanBuilder를 통해 다양한 조건을 동시에 처리해주는 검색 함수 만들수 있다.
이렇게 된다면 여러 개로 쪼개져있는 JPQL을 공통의 목적으로 묶어 기능(역할) 중심의 구조로 설계를 개선할 수 있는 장점들도 존재합니다.
추가 페이징 기법 Page vs Slice
Page : 데이터의 총 개수 및 전체 페이지 수를 알 수 있다. (카운트 쿼리가 발생)
Slice : 다음 슬라이스의 존재 여부를 알 수 있다. (카운트 쿼리 발생 X)
'개발과 > "Spring"이 왔나 봄' 카테고리의 다른 글
| localhost:8080 로그인 창이 뜨는 문제 (0) | 2023.11.16 |
|---|---|
| 첫 Mini project 자랑? 인증? ㅎㅎㅎ (0) | 2023.05.11 |
| troubleshooting : http statusCode (0) | 2023.05.11 |
| 세번째 봄 : AllInOneController의 한계. (0) | 2023.04.21 |
| 두번째 '봄'(Spring) : JPA (0) | 2023.04.17 |