{"id":34,"date":"2022-11-24T15:04:57","date_gmt":"2022-11-24T06:04:57","guid":{"rendered":"https:\/\/kpc2022.satoshis.jp\/?p=34"},"modified":"2022-11-24T15:13:07","modified_gmt":"2022-11-24T06:13:07","slug":"%e6%9c%ac%e3%82%92%e5%89%8a%e9%99%a4%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/kpc2022.satoshis.jp\/?p=34","title":{"rendered":"\u672c\u3092\u524a\u9664\u3059\u308b"},"content":{"rendered":"<p>BookController \u306b\u4ee5\u4e0b\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(&quot;\/delete\/{id}&quot;)\r\n\tpublic ModelAndView delete(ModelAndView mav, @PathVariable long id) {\r\n\t\tmav.setViewName(&quot;delete&quot;);\r\n\t\tOptional&lt;Book&gt; data = repository.findById(id);\r\n\t\tmav.addObject(&quot;book&quot;, data.get());\r\n\t\treturn mav;\r\n\t}\r\n<\/pre>\n<p>\u524a\u9664\u78ba\u8a8d\u753b\u9762\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html xmlns:th=&quot;http:\/\/www.thymeleaf.org&quot;&gt;\r\n&lt;head&gt;\r\n&lt;meta charset=&quot;UTF-8&quot;&gt;\r\n&lt;title&gt;\u672c\u306e\u524a\u9664&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;\u672c\u306e\u524a\u9664&lt;\/h1&gt;\r\n&lt;p&gt;\u3053\u306e\u672c\u3092\u524a\u9664\u3057\u307e\u3059\u304b\uff1f&lt;\/p&gt;\r\n&lt;table&gt;\r\n\t&lt;tr&gt;\r\n\t\t&lt;td&gt;&lt;img class=&quot;book-image&quot; th:src=&quot;${book.image}&quot; \/&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:text=&quot;${book.title}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:text=&quot;${book.author}&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n\r\n&lt;form action=&quot;\/delete&quot; method=&quot;post&quot; th:object=&quot;${book}&quot;&gt;\r\n\t&lt;input type=&quot;hidden&quot; name=&quot;id&quot; th:value=&quot;*{id}&quot; \/&gt;\r\n\t&lt;input type=&quot;submit&quot; value=&quot;\u524a\u9664\u3059\u308b&quot; \/&gt;\r\n&lt;\/form&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>BookController\u306b\u524a\u9664\u78ba\u8a8d\u306ePOST\u3092\u53d7\u3051\u4ed8\u3051\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value = &quot;\/delete&quot;, method = RequestMethod.POST)\r\n\tpublic ModelAndView deleteBook(ModelAndView mav, @RequestParam(&quot;id&quot;) long id) {\r\n\t\tOptional&lt;Book&gt; data = repository.findById(id);\r\n\t\tBook book = data.get();\r\n\t\tBookshelf bookshelf = book.getBookshelf();\r\n\t\tif (bookshelf != null) {\r\n\t\t\tbookshelf.removeBook(book);\r\n\t\t\tbookshelfRepository.saveAndFlush(bookshelf);\r\n\t\t}\r\n\t\trepository.delete(book);\r\n\t\treturn new ModelAndView(&quot;redirect:\/&quot;);\r\n\t}\r\n<\/pre>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>BookController \u306b\u4ee5\u4e0b\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002 \u524a\u9664\u78ba\u8a8d\u753b\u9762\u3092\u8ffd\u52a0\u3059\u308b\u3002 BookController\u306b\u524a\u9664\u78ba\u8a8d\u306ePOST\u3092\u53d7\u3051\u4ed8\u3051\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[3],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-springboot","tag-springboot"],"_links":{"self":[{"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=34"}],"version-history":[{"count":3,"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/34\/revisions"}],"predecessor-version":[{"id":37,"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/34\/revisions\/37"}],"wp:attachment":[{"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}