학습 목표
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
'Spring boot' 카테고리의 다른 글
(스프링 부트 입문)스프링 블로그 프로젝트 만들어보기 (0) | 2025.06.20 |
---|---|
(스프링 부트 입문) 스프링 부트 익명 블로그 만들어 보기(네이티브 쿼리만사용) 1. 게시글 작성 - 네이티브 쿼리 활용 (0) | 2025.06.20 |
(스프링 부트 입문)PUT 방식에 이해 및 실습 (0) | 2025.06.20 |
(스프링 부트 입문 )POST 방식에 이해 및 실습 (0) | 2025.06.19 |
(스프링 부트 기초)GET 방식과 URL 주소 설계 (5) | 2025.06.19 |