| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- transaction
- vue life cycle
- java version
- gradle
- Java
- Vue.js
- 백엔드
- 프론트엔드
- VUE
- 개발자
- 도커
- maven
- RequestBody
- axios
- GIT
- github
- 비동기통신
- fetch
- docker
- git push
- RequestParam
- 트랜잭션
- Spring AOP
- 자바 버전
- aop
- 빌드
- PathVariable
Archives
- Today
- Total
미소의 세상
@RequestParam, @PathVariable, @RequestBody 본문
이 어노테이션들은 controller에서 프론트로부터 파라미터를 전달받을 때 사용하는 어노테이션들이다.
1. @RequestParam
@GetMapping("/food")
public FoodResponseDto findById(@RequestParam(value = "id") Long id) {
return foodService.findById(id);
}
api 요청 시에 URI에 http://localhost:8080/food?id=2 이렇게 queryString 방식으로 넣어주는 것이다.
@RequestParam(value = "id" , required=false) 이렇게 쓰면 id값을 넣어주지 않아도 오류가 발생하지 않는다.
2. @PathVariable
@GetMapping("/api/food/menu/{id}")
public FoodResponseDto findById(@PathVariable Long id) {
return foodService.findById(id);
}
이처럼 api 요청 시에 URI에 http://localhost:8080/api/udong/club/2 이런 식으로 값을 넣어 id 값 = 2 라는 정보를 전달해주는 것이다.
3. @RequestBody
@PostMapping("/api/food/menu")
public Long save(@RequestBody FoodSaveRequestDto requestDto) {
return foodService.save(requestDto);
}
예를들어 프론트에서
{
"id":2,
"name":"김밥"
}
이런 json 형식의 데이터를 서버로 보내주면 이를 받아서 자바 객체 형태로 매핑해준다.
'Spring' 카테고리의 다른 글
| [Spring] AOP 란? (0) | 2022.10.19 |
|---|---|
| Spring boot @Valid 어노테이션 종류 (0) | 2022.04.15 |
| [Spring] @Resource, @Autowired, @Inject 차이 (1) | 2022.03.25 |
| Spring- 필터, 인터셉터 AOP 차이 (0) | 2022.03.11 |
| Spring vs Spring boot 비교 (1) | 2022.02.27 |
Comments