Spring Framework에서 제공하는 클래스 중 HttpEntity라는 클래스를 상속받아 사용하는 클래스
사용자의 HttpRequest에 대한 응답 데이터를 포함
포함하는 클래스
- httpStatus
- HttpHeaders
- HttpBody
package com.example.testproject.controller;
import com.example.testproject.dto.MemberDto;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.lang.reflect.Member;
import java.util.Map;
@RestController
@RequestMapping("/api/v1/put-api")
public class PutController {
@PutMapping(value = "/default")
public String putMethod(){return "Hello putWorld!";}
@PutMapping(value = "/member")
public String postMember(@RequestBody Map<String, Object> postData){
StringBuilder sb = new StringBuilder();
postData.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 MemberDto postMemberDto2(@RequestBody MemberDto memberDto){return memberDto;}
@PutMapping(value = "/member3")
public ResponseEntity<MemberDto> postMemberDto3(@RequestBody MemberDto memberDto){
return ResponseEntity.status(HttpStatus.ACCEPTED).body(memberDto);
// ACCEPTED를 사용하면 202로 뜬다
}
}
package com.example.testproject.controller;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/v1/delete-api")
public class DeleteController {
// http://localhost:8080/api/v1/delete-api/delete/{String 값}
@DeleteMapping(value = "/delete/{variable}")
public String DeleteVariable(@PathVariable String variable){
return variable;
}
}