Path Variable과 Query Parameter

supway·2023년 1월 20일
0

Path Variable

  • 어떤 resource를 식별하고 싶으면 사용
/users/15

    @GetMapping(value = "/{userId}")
    public UserDto findUser(@PathVariable Long userId){
        UserDto foundUser= userService.find(userId);
        return foundUser;
    }

Query Parameter

  • 정렬이나 필터링을 사용할 때 사용
/worker?name=tom&age=12
    @ResponseBody
    @GetMapping("/worker")
    public String requestParamRequired(
            @RequestParam String username, @RequestParam int age){
        UserDto userDto=UserDto.of(username,age);
        return "ok";
    }
    
    @GetMapping("/worker")
    public String requestParamRequired(
            @RequestBody UserRequestDto userRequestDto){
        return "ok";
    }

profile
개발잘하고싶은사람

0개의 댓글