{"id":38,"date":"2022-11-24T15:54:45","date_gmt":"2022-11-24T06:54:45","guid":{"rendered":"https:\/\/kpc2022.satoshis.jp\/?p=38"},"modified":"2022-11-24T16:12:44","modified_gmt":"2022-11-24T07:12:44","slug":"%e6%a5%bd%e5%a4%a9api%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%9c%ac%e3%81%ae%e6%a4%9c%e7%b4%a2","status":"publish","type":"post","link":"https:\/\/kpc2022.satoshis.jp\/?p=38","title":{"rendered":"\u697d\u5929API\u3092\u4f7f\u3063\u305f\u672c\u306e\u691c\u7d22"},"content":{"rendered":"<p>\u307e\u305a\u691c\u7d22\u7528\u306e\u30da\u30fc\u30b8\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>index.html\u306b\u30ea\u30f3\u30af\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\u68da&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;\u672c\u68da&lt;\/h1&gt;\r\n&lt;p&gt;\u672c\u68da\u306e\u30ea\u30b9\u30c8\u3092\u8868\u793a\u3057\u307e\u3059\u3002&lt;\/p&gt;\r\n\r\n&lt;ul th:each=&quot;bs : ${list}&quot;&gt;\r\n\t&lt;li&gt;\r\n\t\t&lt;a th:href=&quot;@{&#039;\/bookshelf\/&#039; + ${bs.id}}&quot; th:text=&quot;${bs.name}&quot;&gt;&lt;\/a&gt;\r\n\t&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n\r\n&lt;form class=&quot;center&quot; action=&quot;\/new-bookshelf&quot; method=&quot;post&quot;&gt;\r\n\t\u540d\u524d: &lt;input class=&quot;w100&quot; type=&quot;text&quot; name=&quot;name&quot; \/&gt;\r\n\t&lt;input type=&quot;submit&quot; value=&quot;\u8ffd\u52a0&quot; \/&gt;\r\n&lt;\/form&gt;\r\n\r\n&lt;h3&gt;&lt;a href=&quot;\/book&quot;&gt;\u672c\u306e\u4e00\u89a7&lt;\/a&gt;&lt;\/h3&gt;\r\n\r\n\r\n&lt;h3&gt;&lt;a href=&quot;\/search&quot;&gt;\u672c\u306e\u691c\u7d22&lt;\/a&gt;&lt;\/h3&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\u30ea\u30f3\u30af\u5148\u306b\u98db\u3070\u3059\u305f\u3081\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306e\u4fee\u6b63\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(&quot;\/search&quot;)\r\n\tpublic ModelAndView search(ModelAndView mav, @RequestParam(&quot;keyword&quot;) String keyword) {\r\n\t\tmav.setViewName(&quot;search&quot;);\r\n\t\treturn mav;\r\n\t}\r\n<\/pre>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f5c\u6210\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\u691c\u7d22&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;\u672c\u306e\u691c\u7d22&lt;\/h1&gt;\r\n\r\n&lt;div&gt;\r\n\t&lt;form action=&quot;\/search&quot; method=&quot;get&quot;&gt;\r\n\t\t&lt;input type=&quot;text&quot; name=&quot;keyword&quot; \/&gt;\r\n\t\t&lt;button&gt;\u691c\u7d22&lt;\/button&gt;\r\n\t&lt;\/form&gt;\r\n&lt;\/div&gt;\r\n\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067\u691c\u7d22\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u53d7\u3051\u53d6\u308c\u308b\u3088\u3046\u306b\u3059\u308b\u3002<br \/>\n\u691c\u7d22\u30ad\u30fc\u30ef\u30fc\u30c9\u304c\u3042\u3063\u305f\u5834\u5408\u306f\u3001\u30c0\u30df\u30fc\u306e\u691c\u7d22\u7d50\u679c\u3092\u8fd4\u3059\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(&quot;\/search&quot;)\r\n\tpublic ModelAndView search(ModelAndView mav,\r\n\t\t\t@RequestParam(name = &quot;keyword&quot;, required = false) String keyword) {\r\n\t\tmav.setViewName(&quot;search&quot;);\r\n\t\tif (keyword != null) {\r\n\t\t\tList&lt;Book&gt; list = rakutenSearch(keyword);\r\n\t\t\tmav.addObject(&quot;list&quot;, list);\r\n\t\t}\r\n\t\treturn mav;\r\n\t}\r\n\r\n\tprivate List&lt;Book&gt; rakutenSearch(String keyword) {\r\n\t\tList&lt;Book&gt; list = new ArrayList&lt;&gt;();\r\n\t\tBook book = new Book();\r\n\t\tbook.setTitle(&quot;\u30bf\u30a4\u30c8\u30eb&quot;);\r\n\t\tbook.setAuthor(&quot;\u8457\u8005&quot;);\r\n\t\tbook.setImage(&quot;https:\/\/cache2-ebookjapan.akamaized.net\/contents\/thumb\/s\/G8100172430561.jpg&quot;);\r\n\t\tlist.add(book);\r\n\t\treturn list;\r\n\t}\r\n<\/pre>\n<p>\u5b9f\u969b\u306b\u691c\u7d22\u3092\u5b9f\u884c\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(&quot;\/search&quot;)\r\n\tpublic ModelAndView search(ModelAndView mav,\r\n\t\t\t@RequestParam(name = &quot;keyword&quot;, required = false) String keyword) {\r\n\t\tmav.setViewName(&quot;search&quot;);\r\n\t\tif (keyword != null) {\r\n\t\t\tList&lt;Book&gt; list = rakutenSearch(keyword);\r\n\t\t\tmav.addObject(&quot;list&quot;, list);\r\n\t\t}\r\n\t\treturn mav;\r\n\t}\r\n\r\n\tprivate List&lt;Book&gt; rakutenSearch(String keyword) {\r\n\t\tString url = makeUrl(keyword);\r\n\t\tSystem.out.println(url);\r\n\t\tRestTemplate restTemplate = new RestTemplate();\r\n\t\tResponseEntity&lt;String&gt; response = restTemplate.exchange(url, HttpMethod.GET, null, String.class);\r\n\t\tString body = response.getBody();\r\n\t\tSystem.out.println(body);\r\n\t\tList&lt;Book&gt; list = new ArrayList&lt;&gt;();\r\n\t\treturn list;\r\n\t}\r\n\r\n\tprivate String makeUrl(String keyword) {\r\n\t\tString url = &quot;https:\/\/app.rakuten.co.jp\/services\/api\/BooksBook\/Search\/20170404?&quot;\r\n\t\t\t\t   + &quot;format=json&quot;\r\n\t\t\t\t   + &quot;&amp;title=&quot; + keyword\r\n\t\t\t\t   + &quot;&amp;booksGenreId=001004008&quot;\r\n\t\t\t\t   + &quot;&amp;applicationId=1042243293332523296&quot;;\r\n\t\treturn url;\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>\u307e\u305a\u691c\u7d22\u7528\u306e\u30da\u30fc\u30b8\u3092\u4f5c\u6210\u3059\u308b\u3002 index.html\u306b\u30ea\u30f3\u30af\u3092\u8ffd\u52a0\u3059\u308b\u3002 \u30ea\u30f3\u30af\u5148\u306b\u98db\u3070\u3059\u305f\u3081\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306e\u4fee\u6b63\u3002 \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3002 \u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067\u691c\u7d22\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u53d7\u3051\u53d6\u308c\u308b\u3088\u3046\u306b\u3059\u308b\u3002  &#8230; <\/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-38","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\/38","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=38"}],"version-history":[{"count":3,"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/38\/revisions"}],"predecessor-version":[{"id":41,"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/38\/revisions\/41"}],"wp:attachment":[{"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kpc2022.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}