We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// plugins에 추가 id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10' // Querydsl // dependencies에 추가 implementation 'com.querydsl:querydsl-jpa' // 그 아래 추가 def querydslDir = "$buildDir/generated/querydsl" querydsl { jpa = true querydslSourcesDir = querydslDir } sourceSets { main.java.srcDir querydslDir } configurations { querydsl.extendsFrom compileClasspath } compileQuerydsl { options.annotationProcessorPath = configurations.querydsl }
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.querydsl.QuerydslPredicateExecutor; import org.zerock.guestbook.entity.Guestbook; public interface GuestbookRepository extends JpaRepository<Guestbook, Long>, QuerydslPredicateExecutor<Guestbook> { }
공식 문서(한글)
공식 문서(영어)
... @Test @DisplayName("Querydsl로 title 검색 조건을 처리한다.") void test_Querydsl1() { /* given */ Pageable pageable = PageRequest.of(0, 10, Sort.by("gno").descending()); QGuestbook qGuestbook = QGuestbook.guestbook; String keyword = "20"; // BooleanBuilder -> Where 문에 들어가는 조건들을 넣어주는 컨테이너 BooleanBuilder builder = new BooleanBuilder(); /* when */ BooleanExpression expression = qGuestbook.title.contains(keyword); builder.and(expression); Page<Guestbook> result = guestbookRepository.findAll(builder, pageable); /* then */ result.stream().forEach(System.out::println); } @Test @DisplayName("Querydsl로 다중 항목 검색 조건을 처리한다.") void test_Querydsl2() { /* given */ Pageable pageable = PageRequest.of(0, 50, Sort.by("gno").ascending()); QGuestbook qGuestbook = QGuestbook.guestbook; String titleKeyword = "10"; String contentKeyword = "20"; BooleanBuilder builder = new BooleanBuilder(); /* when */ BooleanExpression exTitle = qGuestbook.title.contains(titleKeyword); BooleanExpression exContent = qGuestbook.content.contains(contentKeyword); BooleanExpression exAll = exTitle.or(exContent); builder.and(exAll); builder.and(qGuestbook.gno.gt(0L)); Page<Guestbook> result = guestbookRepository.findAll(builder, pageable); /* then */ result.stream().forEach(System.out::println); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Querydsl 프로젝트 설정(build.gradle)
Querydsl
공식 문서(한글)
공식 문서(영어)
The text was updated successfully, but these errors were encountered: