[Spring] @PathVariable에 대한 나름의 이해
2023. 12. 24. 19:48ㆍSpring
@PathVariable은 request url에 들어있는 값을 변수로 가지고 오고 싶을때 사용한다.
예를 들어, 다음을 보자.
@GetMapping("/download/{contentId}")
public ResponseEntity<Resource> downloadFile(@PathVariable("contentId") Long contentId) throws IOException {
내가 변수로 설정하고 싶은 부분을 request url에서 {name}으로 담는다.
그리고 메소드 파라미터에 @PathVariable("name") type variable을 넣어주면 name의 값을 variable에 값이 담겨 이를 사용할 수 있다.
'Spring' 카테고리의 다른 글
[Spring] Error resolving template 문제 해결 (0) | 2023.12.24 |
---|---|
[Spring] h2를 간단하게 메모리로 돌리기 (0) | 2023.12.24 |
[Spring] 타임리프로 이미지 넣기 (0) | 2023.12.24 |
[Spring] MVC 패턴에 대해 (1) | 2023.12.17 |
[Spring] Controller에 대한 나름의 이해 (0) | 2023.12.17 |