BoardSearchImpl
페이지 정보
본문
package web.repository;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.JPQLQuery;
import web.domain.Board;
import web.domain.QBoard;
public class BoardSearchImpl extends QuerydslRepositorySupport implements BoardSearch{
public BoardSearchImpl() {
super(Board.class);
}
@Override
public Page<Board> searchAll(String[] types, String keyword, Pageable pageable) {
QBoard board = QBoard.board; //Q도메인 객체 선언 및 초기화
JPQLQuery<Board> query = from(board); //select ... from board (쿼리 부분)
//검색 타입과 검색어가 있다면
if( (types != null && types.length > 0) && keyword != null ) {
BooleanBuilder booleanBuilder = new BooleanBuilder();
for(String type : types) {
switch (type){
case "t":
booleanBuilder.or(board.title.contains(keyword));
break;
case "c":
booleanBuilder.or(board.content.contains(keyword));
break;
case "w":
booleanBuilder.or(board.writer.contains(keyword));
break;
} //switch
} //for
query.where(booleanBuilder);
} //if
query.where(board.bno.gt(0L));
//paging
this.getQuerydsl().applyPagination(pageable, query);
List<Board> list = query.fetch();
long count = query.fetchCount();
return null;
}
@Override
public Page<Board> search1(Pageable pageable) {
QBoard board = QBoard.board; //Q도메인 객체 선언 및 초기화
JPQLQuery<Board> query = from(board); //select ... from board (쿼리 부분)
query.where(board.title.contains("1")); //where title like '%1%' (쿼리 부분)
//paging
this.getQuerydsl().applyPagination(pageable, query);
List<Board> list = query.fetch();
long count = query.fetchCount();
return null;
}
}
- 이전글BoardSearch 24.06.17
- 다음글BoardRepositoryTest 24.06.17
댓글목록
등록된 댓글이 없습니다.