Spring Boot Request Method

devyunie·2024년 8월 22일

SpringBoot

목록 보기
4/13
post-thumbnail

Request Method

경로가 동일하더라도 호출하는 method가 GET, POST, PUT, PATCH, DELETE 인가에 따라서 다른 결과 값이 반환


@GetMapping()

  • HTTP GET method
    - 클라이언트가 서버로부터 데이터를 받기위한 메서드
    - Request Body가 존재하지 않음
@GetMapping("/")
public String getMethod(){
	return "GET Method";
}

@PostMapping()

  • HTTP POST method
    - 클라이언트가 서버에 리소스를 작성하기 위한 메서드
    - Request Body가 존재함
@PostMapping("")
public String postMethod(){
	return "Post Method";
}

@PutMapping()

  • HTTP PUT method
    - 클라이언트가 서버에 리소스를 전체 수정하기 위한 메서드
    - Request Body가 존재함
@PutMapping("")
public String putMethod(){
	return "put Method";
}

@PatchMapping()

  • HTTP PATCH method
    - 클라이언트가 서버에 리소스를 일부 수정하기 위한 메서드
    - Request Body가 존재함
@PatchMapping("")
public String patchMethod(){
	return "patch Method";
}

@DeleteMapping()

  • HTTP DELETE method
    - 클라이언트가 서버에 리소스를 삭제하기 위한 메서드
    - Request Body가 존재하지 않음
@DeleteMapping("")
public String deleteMethod(){
	return "Delete Method";
}

⚠️주의

  • Method + URL Pattern이 중복되면 서버 실행중에 에러가 발생
@GetMapping("/first")
public String getFirst(){
	return "get First";
}

0개의 댓글