본문 바로가기

SPRING

[SPRING] RequestMapping URL pathVariable에 null 값 허용하는 방법

 

spring boot 로 API 를 만드는데 pathVariable에 null값이 들어가게 호출을 해야하는 상황이다

 

즉,

method = GET, URL = test/detail/{detailNo}

method = GET, URL = test/detail

이렇게 두개의 API가 하나의 컨트롤러에서 호출 되도록하고 싶음 

 

해결방안 : 

@GetMapping 어노테이션 대신 @RequestMapping 어노테이션을 사용하여 value 속성을 추가하면 된다고 한다

 

@RequestMapping(value = {"/test/detail/{detailNo}", "/test/detail/"})

 

 

 

적용 예시

 

 

 

 

끄읏 -!