회원 관리를 HTTP API로 만든다 생각하고 매핑을 어떻게 하는지 알아보았다.
회원 관리API
회원 목록 조회 : GET /users
회원 등록 : POST /users
회원 조회 : GET /uesrs/{userID}
회원 수정 : PATCH /users/{userID}
회원 삭제 : DELETE /users/{userID}
package hello.springmvc.basic.requestmapping;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/mapping/users")
public class MappingClassController {
@GetMapping
public String users(){
return "get users";
}
@PostMapping
public String addUser(){
return "post user";
}
@GetMapping("/{userId}")
public String findUser(@PathVariable String userId){
return "get userID";
}
@PatchMapping("/{userId}")
public String updateUser(@PathVariable String userId){
return "update userId=" + userId;
}
@DeleteMapping("/{userId}")
public String deleteUser(@PathVariable String userId){
return "delete userId=" +userId;
}
}
깔끔하게 API만 설계 해보았다.
'웹프로그래밍 > 스프링 MVC' 카테고리의 다른 글
| 42. HTTP 요청 파라미터 - 쿼리 파라미터, HTML Form (0) | 2022.04.04 |
|---|---|
| 41. HTTP 요청 - 기본, 헤더 조회 (0) | 2022.04.04 |
| 39. 요청 매핑 (0) | 2022.04.03 |
| 38. 로깅 간단히 알아보기 (0) | 2022.04.02 |
| 37. 프로젝트 생성 (0) | 2022.04.02 |