-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from Sirius506775/develope
Querydsl를 이용한 검색과 페이징 기능 구현
- Loading branch information
Showing
17 changed files
with
297 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/hallym/festival/domain/booth/repository/boothSearch/BoothSearch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.hallym.festival.domain.booth.repository.boothSearch; | ||
|
||
import com.hallym.festival.domain.booth.entity.Booth; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface BoothSearch { | ||
|
||
Page<Booth> search1(Pageable pageable); | ||
|
||
Page<Booth> searchAll(String[] types, String keyword, Pageable pageable); | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/com/hallym/festival/domain/booth/repository/boothSearch/BoothSearchImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.hallym.festival.domain.booth.repository.boothSearch; | ||
|
||
import com.hallym.festival.domain.booth.entity.Booth; | ||
import com.hallym.festival.domain.booth.entity.QBooth; | ||
import com.querydsl.core.BooleanBuilder; | ||
import com.querydsl.jpa.JPQLQuery; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; | ||
|
||
import java.util.List; | ||
|
||
public class BoothSearchImpl extends QuerydslRepositorySupport implements BoothSearch { | ||
|
||
public BoothSearchImpl(){ | ||
super(Booth.class); | ||
} | ||
|
||
@Override | ||
public Page<Booth> search1(Pageable pageable) { | ||
|
||
QBooth booth = QBooth.booth; | ||
|
||
JPQLQuery<Booth> query = from(booth); //@Query로 생성했던 JPQL을 코드로 생성 | ||
|
||
BooleanBuilder booleanBuilder = new BooleanBuilder(); // ( | ||
|
||
booleanBuilder.or(booth.booth_title.contains("11")); // title like ... | ||
|
||
booleanBuilder.or(booth.booth_content.contains("11")); // content like .... | ||
|
||
query.where(booleanBuilder); | ||
query.where(booth.bno.gt(0L)); //bno가 0보다 큰 조건 | ||
|
||
|
||
//paging | ||
this.getQuerydsl().applyPagination(pageable, query); | ||
|
||
List<Booth> list = query.fetch(); //JPQLQuery 실행 | ||
|
||
long count = query.fetchCount(); //fetchCount()로 count 쿼리 실행 | ||
|
||
|
||
return null; | ||
|
||
} | ||
|
||
@Override | ||
public Page<Booth> searchAll(String[] types, String keyword, Pageable pageable) { | ||
|
||
QBooth booth = QBooth.booth; | ||
JPQLQuery<Booth> query = from(booth); | ||
|
||
if( (types != null && types.length > 0) && keyword != null ){ //검색 조건과 키워드가 있다면 | ||
|
||
BooleanBuilder booleanBuilder = new BooleanBuilder(); // ( | ||
|
||
for(String type: types){ | ||
|
||
switch (type){ | ||
case "t": | ||
booleanBuilder.or(booth.booth_title.contains(keyword)); | ||
break; | ||
case "c": | ||
booleanBuilder.or(booth.booth_content.contains(keyword)); | ||
break; | ||
case "w": | ||
booleanBuilder.or(booth.writer.contains(keyword)); | ||
break; | ||
} | ||
}//end for | ||
query.where(booleanBuilder); | ||
}//end if | ||
|
||
//bno > 0 | ||
query.where(booth.bno.gt(0L)); | ||
|
||
//paging | ||
this.getQuerydsl().applyPagination(pageable, query); | ||
|
||
List<Booth> list = query.fetch(); | ||
|
||
long count = query.fetchCount(); | ||
|
||
return new PageImpl<>(list, pageable, count); | ||
//페이징의 최종 처리는 Page<T>타입을 반환합니다. (실제 목록 데이터, 페이지 정보를 가진 객체, 전체개수) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.