자기계발/활동&해커톤&코테후기

[spring]@PathVariable, @RequestParam

개발자 덕구🐾 2022. 8. 20. 22:50
728x90

 

 

1. @RequestParam

 

 

예시로 

 

 

?festivalIdx = 

@GetMapping("")
    @ResponseBody
    public BaseResponse<GetFestivalByFestivalIdxRes> getFestivalByFestivalIdx(@RequestParam("festivalIdx") int festivalIdx) {
        try {
            GetFestivalByFestivalIdxRes getFestivalByFestivalIdxRes = festivalProvider.getFestivalByFestivalIdx(festivalIdx);
            return new BaseResponse<>(getFestivalByFestivalIdxRes);
        } catch (BaseException e) {
            return new BaseResponse<>(e.getStatus());
        }
    }

 

 

 

 

 

 

 

2. @PathVariable

 

/3 

 festivalidx 가 3인 put 

 

@PutMapping("/{festivalIdx}")
    @ResponseBody
    public BaseResponse<String> modifyFestival(@PathVariable int festivalIdx, @RequestBody PutFestivalReq putFestivalReq) {
        try {
            festivalService.modifyFestival(festivalIdx, putFestivalReq);
            String result = "수정이 완료되었습니다.";
            return new BaseResponse<>(result);

        } catch (BaseException e) {
            return new BaseResponse<>(e.getStatus());
        }
    }

 

 

 

반응형