[Spring] Rest-swagger - PUT + DELETE

์ง„์ฃผยท2022๋…„ 3์›” 18์ผ
0

Spring

๋ชฉ๋ก ๋ณด๊ธฐ
12/29
post-thumbnail

๐Ÿฅ— Controller.java

  // PUT Methods
  @PutMapping("/book")
  public BookDto updateBook(@RequestBody BookDto bookDto){
    BookDto book = bookDto;
    return book;
  }


  // Delete Methods
  @DeleteMapping("book/{bookName}")
  public String deleteBook(@PathVariable String bookName){
    // delete SQL ์‹คํ–‰

    return "book : " + bookName + "์ด ์ œ๊ฑฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.";
  }

PUT

์ฝ”๋“œ ์ถ”๊ฐ€, ์„œ๋ฒ„ ์žฌ์‹คํ–‰

PUT ํด๋ฆญ ํ›„, BODY ๋ถ€๋ถ„์˜ JSON ๋ฐ์ดํ„ฐ author ๋ถ€๋ถ„ ๋ณ€๊ฒฝ

{
  "name" : "๊น€๋นต๋นต์€ ๋ˆ„๊ตฌ์ธ๊ฐ€",
  "author" : "๊น€์ˆœ์ž๊ฐ€ ์•„๋‹Œ ๊น€๋นต๋นต"
}

author์ด ๊น€์ˆœ์ž์—์„œ ๊น€์ˆœ์ž๊ฐ€ ์•„๋‹Œ ๊น€๋นต๋นต์œผ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค.


Delete

PUT ์—์„œ DELETE๋กœ ๋ณ€๊ฒฝ

http://localhost:8090/api/v1/book/๊น€๋นต๋นต์€๋ˆ„๊ตฌ์ธ๊ฐ€ ์ž…๋ ฅ ํ›„, Send ํด๋ฆญ

Response Body๋ถ€๋ถ„์— DELETE๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๊ณ  ์ถœ๋ ฅํ•œ๋‹ค.

profile
์ง„์ฃผ์˜ ์ฝ”๋”ฉ์ผ๊ธฐ

0๊ฐœ์˜ ๋Œ“๊ธ€