Querydsl 지원 클래스를 사용할때 sort 익셉션 처리관련 질문
307
작성한 질문수 44
QueryDsl 지원 클래스를 직접 사용할 경우, paging, sorting의 로직을 한곳에서 관리할 수 있는데
@GetMapping("/search")
public ResponseEntity<ResponseOKDto<GetPagePostsResponseDto>> getPagePostsSearch(
PostSearchCondition condition,
Pageable pageable, @ApiIgnore HttpSession session){
Account account = accountService.checkSessionAndFindAccountWithActivityArea(session);
Page<Post> pagePost = checkStatusParamAndFindPosts(account, condition, pageable);
return new ResponseEntity<>(new ResponseOKDto<>(new GetPagePostsResponseDto(pagePost)), HttpStatus.OK);
}
이런식으로 만들었을 경우, 프론트에서 해당 도메인 클래스에 없는 프로퍼티에 대해 잘못 sorting을 요청했을 때 익셉션 처리를 해주려고하는데요
querydsl 지원 클래스내에서 해당 익셉션을 처리할 경우,
아래와 같이 다른 도메인 controller에서도 따로 익셉션을 처리하지 않아도 된다는 장점을 가지는 것 같은데요
protected <T> Page<T> applyPagination(Pageable pageable, Function<JPAQueryFactory, JPQLQuery> contentQuery,
Function<JPAQueryFactory, JPQLQuery> countQuery){
checkSortProperties(pageable);
JPQLQuery jpaContentQuery = contentQuery.apply(queryFactory);
JPQLQuery jpaCountQuery = countQuery.apply(queryFactory);
List<T> content = getQuerydsl().applyPagination(pageable, jpaContentQuery).fetch();
return PageableExecutionUtils.getPage(content, pageable, jpaCountQuery::fetchCount);
}
private void checkSortProperties(Pageable pageable) {
List<String> domainFields = Arrays.stream(domainClass.getDeclaredFields()).map(Field::getName).collect(toList());
List<String> sortFields = pageable.getSort().get().map(Sort.Order::getProperty).collect(toList());
if (!domainFields.containsAll(sortFields)) {
throw new IllegalSortArgumentException("invalid sort property, properties must be in " + domainFields);
}
}
고민이 되는 점은 컨트롤러에서 미리 걸러줘야 할 것 같은데,
레포지토리내에서 익셉션 처리를 해줘도 되나?라는 의문이 들었습니다.
익셉션 처리 위치를 이렇게 해줘도 될까요?
아니면 번거롭더라도 각각의 도메인에 대해 일일히 컨트롤러 클래스 내에서 처리를 해줘야 할까요?
답변주시면 감사드리겠습니다.
답변 1
SpringBoot 4.X에서의 Querydsl 설정
0
88
2
querydsl 오픈소스에 대한 질문
0
72
1
예제에서의 카운트 쿼리에서 join문과 where문은 필요없지 않나요?
0
109
1
Querydsl 6.X버전에 대해서 어떻게 생각하시나요?
0
317
2
여러 테이블 조인하여 통계치를 구하고자 할 때 어떤 방법이 더 효율적일까요
1
70
1
fetchResults()는 더이상 권장되지 않는다는데 맞나요?
0
160
1
querydsl sum() 메서드 없어요.
0
159
2
build 디렉터리 생성
0
136
2
자바 ORM 표준 JPA 프로그래밍 - 기본편 듣고 바로 학습해도 괜찮을까요?
0
114
2
현재 Querydsl에서 from절 서브쿼리를 지원하나요?
0
91
1
오타 제보 드립니다.
0
72
2
벌크 연산과 flush, clear
0
76
1
Run As Intellij 로 변경시 Q타입 import 불가
0
88
1
QHello import하기 문제 발생
0
147
2
등록된 함수 보는법(H2Dialect) 질문
0
68
2
5.0부터 Querydsl은 향후 fetchCount() , fetchResult() 를 지원하지 않기로 결정했다고 하는데 이에 맞는 강의
1
197
2
[환경설정 PDF 부트 3.0이후 설명 질문] build.gradle에 compileQuerydsl을 정의하지 않은 상태에서 Gradle->Tasks->other->compileQuerydsl을 클릭하라고 하는 이유가 무엇인가요??
1
200
1
querydsl 설정 문제
0
222
2
quey dsl 설정부분
0
158
2
count 쿼리 관련 질문입니다!
0
75
1
stringtemplate를 이용하여 where절 검색 방법 질문 드립니다.
0
89
1
답변부탁드리겠습니다.
0
89
2
(OrderSpecifier)관련 내용 어디있을가요
0
65
1
중급문법 벌크연산에서
0
81
2





