Java & Spring & SpringBoot
Spring @RequestMapping에서 @PathVariable 허용된 값만 사용하는 법
Grand_J
2023. 7. 20. 16:18
반응형
Spring @RequestMapping에서 @PathVariable 허용된 값만 사용하는 법
@GetMapping("/type/{type:id|name}")
public HttpEntity selectTestList(@PathVariable String type){
return new HttpEntity<>("");
}
localhost:8080/type/id 200 ok
localhost:8080/type/name 200 ok
localhost:8080/type/phone 404 error
// @RequestMapping 사용 가능
@RequestMapping("/type/{type:id|name}")
Enum을 이용해서 해도 되지만 간단하게 허용 데이터 작업할때 사용
ㄲ듯ㄷㅈㄱ4ㅏㅣ!@#
반응형