SPRING-JPA 에서 QueryDSL사용을 위한 단계
- Entity QDomain 메타 지원을 위한 pom.xml 수정
- 기존 Repository 인터페이스에서, QueryDslPredicateExecutor 추가 상속받음
- Builder 클래스를 통해 각종 검색옵션 조합하여 , 기존 쿼리메스드(findall()) 에 인자값으로 전달가능
Spring-Boot-Starter 에서 QueryDSL 사용을 위한 pom.xml 수정
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> ..................... <dependencies> ..................... <dependency> <groupId>com.querydsl</groupId> <artifactId>querydsl-core</artifactId> <version>4.1.3</version> </dependency> <dependency> <groupId>com.querydsl</groupId> <artifactId>querydsl-jpa</artifactId> <version>4.1.3</version> </dependency> ..................... </dependencies> ..................... <build> <plugins> <!-- MUST add to use generate QueryDSL --> <plugin> <groupId>com.mysema.maven</groupId> <artifactId>apt-maven-plugin</artifactId> <version>1.1.3</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>process</goal> </goals> <configuration> <!-- Specifies the directory in which the query types are generated --> <outputDirectory>target/generated-sources/querydsl</outputDirectory> <!-- States that the APT code generator should look for JPA annotations --> <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>com.querydsl</groupId> <artifactId>querydsl-apt</artifactId> <version>4.1.3</version> </dependency> </dependencies> </plugin> </plugins> </build> .....................
QueryDSL지원을 위한 Repository 정의
Table Entity정의는 기존과 동일합니다. 차이점이 있다면, pom.xml에서 QueryDSL지원을 위한 메타빌드로 설정했기때문에
Address라고 정의한 Entity가 QueryDSL에서는 QAddress 라는 도메인 객체를 자동 생성합니다.