@PutMapping(value = "/default")
public String putMethod() {
return "Hello World!";
}
@PutMapping(value = "/member")
public String postMember(@RequestBody Map<String, Object> putData) {
StringBuilder sb = new StringBuilder();
putData.entrySet().forEach(map -> {
sb.append(map.getKey() + " : " + map.getValue() + "\n");
});
return sb.toString();
}
@PutMapping(value = "/member1")
public String postMemberDto1(@RequestBody MemberDTO memberDTO) {
return memberDTO.toString();
}
@PutMapping(value = "/member2")
public String postMemberDto2(@RequestBody MemberDTO memberDTO) {
return memberDTO; // JSON의 형태로 return
}
@PathVariable
을 통해 리소스 ID 등을 받아 처리@DeleteMapping(value = "/delete/{variable}")
public String DeleteVariable(@PathVariable String variable) {
return variable;
}
Status를 더 디테일하게 수정하기 위해
@PutMapping(value = "/member3")
public String postMemberDto3(@RequestBody MemberDTO memberDTO) {
return ResponseEntity.status(HttpStatus.ACCEPTED).body(memberDTO); // Code: 202
}
참고 영상
PUT API, DELETE API 작성하는 방법 | ResponseEntity [ 스프링 부트 (Spring Boot) ]