study를 조회할 때 @PathVariable로 studyId로 조회하는 것과 @RequestParam으로 participantCode로 조회하는 것을 묶어보았다.
@GetMapping("/api/studies/{studyId}")
public ResponseEntity<PomodoroRoomResponse> findStudy(
@PathVariable(required = false) Long studyId,
@RequestParam(required = false) String participantCode
) {
PomodoroRoomResponse pomodoroRoom = pomodoroRoomService.findPomodoroRoomWithFilter(studyId,
participantCode);
return ResponseEntity.ok(pomodoroRoom);
}
@PathVariable과 @RequestParam 둘 다 require가 default ture이고 required = false로 설정하면 다음과 같이 두 요청 모두 핸들링이 가능하다고 생각했다.
- /api/stuides/{studyId}
- /api/studies?participantCode
하지만 @PathVVariable의 required를 false를 하더라도 다음과 같이 예상한대로 작동하지는 않는다.
@PathVariable에 required를 false를 하더라도 /api/stuides/{studyId} 형태가 아니면 핸들러 맵핑이 안되는 것.
이러한 경우는 핸들러를 분리하여 따로 작성해야 한다.
'회고 > 우아한테크코스' 카테고리의 다른 글
[JPA] 테스트 데이터를 엔티티로 셋팅하며 발생한 이슈 (0) | 2023.09.27 |
---|---|
다양한 방법으로 수행한 JPQL 쿼리 및 실행 계획 확인 (0) | 2023.08.17 |
2023.08.08 일일 회고 (0) | 2023.08.09 |
2023.07.31 일일 회고 (1) | 2023.08.01 |
2023.07.21 일일 회고 (0) | 2023.07.21 |