-
HTTP 요청 맵핑하기 7부: 맵핑 연습 문제SPRING/스프링 MVC 2021. 6. 27. 15:57
다음 요청을 처리할 수 있는 핸들러 메소드를 맵핑하는
@RequestMapping (또는 @GetMapping, @PostMapping 등)을 정의하세요.
1. GET /events
2. GET /events/1,
GET /events/2,
GET /events/3,
3. POST /events CONTENT-TYPE: application/json ACCEPT: application/json
4. DELETE /events/1,
DELETE /events/2,
DELETE /events/3,
5. PUT /events/1 CONTENT-TYPE: application/json ACCEPT: application/json,
PUT /events/2 CONTENT-TYPE: application/json ACCEPT: application/json, ...
@Controller public class SampleController5 { // 1번 @GetMapping("/events") @ResponseBody public String events() { return "events"; } // 2번 @GetMapping("/events2/{id}") @ResponseBody public String events2(@PathVariable int id) { return "events"; } //3번 @PostMapping( value = "/events", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE ) @ResponseBody public String events3() { return "events"; } // 4번 @DeleteMapping("/events/{id}") @ResponseBody public String events4(@PathVariable int id) { return "events"; } //5번 @PutMapping( value ="/events/{id}",consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public String events5(@PathVariable int id) { return "events"; } }
'SPRING > 스프링 MVC' 카테고리의 다른 글
핸들러 메소드 3부: @RequestParam (0) 2021.06.30 핸들러 메소드 2부: URI 패턴 (0) 2021.06.27 요청 맵핑하기 6부 커스텀 애노테이션 (0) 2021.06.27 HTTP 요청 맵핑하기 4부: 헤더와 매개변수 (0) 2021.06.26 HTTP 요청 맵핑하기 3부: 미디어 타입 맵핑 (0) 2021.06.26