스프링 Multiple PathVariable 설정하기

  • xixixaxa
    (OOooOOoo)
  • xixixaxa's Avatar 이 글의 작성자
  • Offline
  • Newbie
  • Newbie
더보기
10 May 2022 17:34 #31887 작성자: xixixaxa
xixixaxa 님의 글: 스프링 Multiple PathVariable 설정하기
@GetMapping("/api/employees/{id}/{name}")
@ResponseBody
public String getEmployeesByIdAndName(@PathVariable String id, @PathVariable String name) {
    return "ID: " + id + ", name: " + name;
}
@GetMapping("/api/employeeswithmapvariable/{id}/{name}")
@ResponseBody
public String getEmployeesByIdAndNameWithMapVariable(@PathVariable Map<String, String> pathVarsMap) {
    String id = pathVarsMap.get("id");
    String name = pathVarsMap.get("name");
    if (id != null && name != null) {
        return "ID: " + id + ", name: " + name;
    } else {
        return "Missing Parameters";
    }
}

출처 : www.baeldung.com/spring-pathvariable
Time to create page: 0.053 seconds
Powered by Kunena Forum