Spring boot

(스프링 부트)DELETE 방식에 이해 및 실습

mynote6676 2025. 6. 20. 23:12

학습 목표

1.@DeleteMapping 이해

2.@PathVariable 사용

3.@RequsetParam 사용

 

package com.example.demo1.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
// 컴포넌트 스캔에 대상 --> IoC(제어의 역전) --> 스프링 컨테이너 안에 싱글톤 패턴으로 관리 됨
public class DeleteApiController {

    /**
     * DELETE 요청 처리
     * 웹 브라우저 주소창에서 사용이 불가
     * HTTP 요청 메시지에 본문이 없다
     * 주소 설계
     * http://localhost:8080/delete/100?account=우리은행
     */
    @DeleteMapping("/delete/{userId}")
    public ResponseEntity<?>  delete(@PathVariable(name = "userId") String userId,
                                    @RequestParam(name = "account") String account) {
        System.out.println("userId : " + userId);
        System.out.println("account : " + account);
        // ResponseEntity responseEntity = new ResponseEntity();
        // HTTP - 404 <--- 페이지를 찾을 수 없음
        return ResponseEntity.status(HttpStatus.OK).body("정상삭제완료");
         
    }
}

 

728x90