Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Everything has an expiration date

★ ResponseEntity @PathVariable 본문

카테고리 없음

★ ResponseEntity @PathVariable

Jelly-fish 2024. 4. 18. 13:14

 

Ⅰ. ResponseEntity

`ResponseEntity` 란 ? 

 

우리가 RestController 로 개발할 때는 문서가 아니라 데이터를 반환하잖아?

ResponseEntity를 사용하면 데이터랑 상태코드를 같이 반환할 수 있어

 

@GetMapping("/customer-list")
ResponseEntity<ArrayList<CustomerVO>> getCustomerList() {

    return new ResponseEntity<>(custService.getCustomerList(), HttpStatus.OK);
                                -----------------------------  --------------
                                           ① 데이터              ② 상태 코드
}

 

`return new ResponseEntity<>(custService.getCustomerList(), HttpStatus.OK);}`
이거 보면 첫 번째 인자가 데이터, 두 번째 인자가 상태 코드 ~

 

Ⅱ. @PathVariable 

`@PathVariable` 이란?

 

http://localhost:4306/api/customer/edit/1
                                     ★===
                             이거!! 이걸 받을 수 있다~!!

 

url에서 query string 말고 `/customers/1` 과 같이 작성할 때 
1이라는 데이터를 받을 수 있는 어노테이션입니다~



문서(HTML)는 그냥 Controller ~!!
Data는 RestController~!!!

 

 

 

 

 

SpringBoot 너무 뭔가 복잡해... 설명 잘 해주셔서 이해하긴 했는데... 으음........................................ 내 꿈은 SpringBoot 마스터