{"id":71,"date":"2020-11-12T13:50:43","date_gmt":"2020-11-12T04:50:43","guid":{"rendered":"http:\/\/kpc2020.satoshis.jp\/?p=71"},"modified":"2020-11-12T14:45:23","modified_gmt":"2020-11-12T05:45:23","slug":"spring-boot%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6web%e3%82%a2%e3%83%97%e3%83%aa%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b-%e3%81%9d%e3%81%ae3","status":"publish","type":"post","link":"https:\/\/kpc2020.satoshis.jp\/?p=71","title":{"rendered":"Spring Boot\u3092\u4f7f\u3063\u3066Web\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3059\u308b \u305d\u306e3"},"content":{"rendered":"<p>Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8d77\u52d5\u3059\u308b\u305f\u3073\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u521d\u671f\u5316\u3055\u308c\u3066\u3057\u307e\u3046\u8a2d\u5b9a\u306b\u306a\u3063\u3066\u3044\u305f\u306e\u3067\u3001\u305d\u308c\u3092\u4fee\u6b63\u3059\u308b\u3002<\/p>\n<p>application.properties<\/p>\n<pre class=\"brush: plain; highlight: [5]; title: ; notranslate\" title=\"\">\r\nspring.datasource.url=jdbc:hsqldb:hsql:\/\/localhost\/shindan\r\nspring.datasource.username=SA\r\nspring.datasource.password=\r\nspring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver\r\nspring.jpa.hibernate.ddl-auto=update\r\n<\/pre>\n<p>IndexController.java<\/p>\n<pre class=\"brush: java; highlight: [25,26,45,46]; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport java.util.List;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.servlet.ModelAndView;\r\n\r\n@Controller\r\npublic class IndexController {\r\n\t@Autowired\r\n\tprivate ShindanRepository repository;\r\n\r\n\t@RequestMapping(&quot;\/&quot;)\r\n\tpublic String index() {\r\n\t\treturn &quot;index&quot;;\r\n\t}\r\n\r\n\t@RequestMapping(value=&quot;\/form&quot;, method=RequestMethod.GET)\r\n\tpublic ModelAndView form(ModelAndView mav) {\r\n\t\tmav.setViewName(&quot;form&quot;);\r\n\t\tList&lt;Shindan&gt; list = repository.findAll();\r\n\t\tmav.addObject(&quot;list&quot;, list);\r\n\t\treturn mav;\r\n\t}\r\n\r\n\t@RequestMapping(value=&quot;\/form&quot;, method=RequestMethod.POST)\r\n\tpublic ModelAndView formPost(ModelAndView mav,\r\n\t\t\t@RequestParam(&quot;name&quot;) String name,\r\n\t\t\t@RequestParam(&quot;eval&quot;) String eval) {\r\n\t\tint percent = (name + eval).hashCode() % 101;\r\n\t\tpercent = Math.abs(percent);\r\n\r\n\t\tShindan shindan = new Shindan();\r\n\t\tshindan.setName(name);\r\n\t\tshindan.setEval(eval);\r\n\t\tshindan.setPercent(percent);\r\n\t\trepository.saveAndFlush(shindan);\r\n\t\tString result = name + &quot; \u3055\u3093\u306e&quot; + eval + &quot;\u5ea6\u306f&quot; + percent + &quot;%\u3067\u3059\uff01\uff01\uff01&quot;;\r\n\t\tmav.addObject(&quot;result&quot;, result);\r\n\r\n\t\tList&lt;Shindan&gt; list = repository.findAll();\r\n\t\tmav.addObject(&quot;list&quot;, list);\r\n\t\tmav.setViewName(&quot;form&quot;);\r\n\t\treturn mav;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>form.html<\/p>\n<pre class=\"brush: xml; highlight: [24,25]; 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;\u8a3a\u65ad\u30da\u30fc\u30b8&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;\u8a3a\u65ad\u30da\u30fc\u30b8&lt;\/h1&gt;\r\n\r\n&lt;p th:text=&quot;${result}&quot;&gt;&lt;\/p&gt;\r\n\r\n&lt;form action=&quot;\/form&quot; method=&quot;post&quot;&gt;\r\n\t\u304a\u306a\u307e\u3048: &lt;input type=&quot;text&quot; name=&quot;name&quot; \/&gt;\r\n\t&lt;br \/&gt;\r\n\t\u8a3a\u65ad: &lt;input type=&quot;text&quot; name=&quot;eval&quot; \/&gt;\r\n\t&lt;input type=&quot;submit&quot; value=&quot;\u8a3a\u65ad&quot; \/&gt;\r\n&lt;\/form&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;h3&gt;\u3053\u308c\u307e\u3067\u306e\u8a3a\u65ad\u7d50\u679c&lt;\/h3&gt;\r\n&lt;table&gt;\r\n\t&lt;tr th:each=&quot;s : ${list}&quot;&gt;\r\n\t\t&lt;td th:text=&quot;${s.name} + ' \u3055\u3093\u306e ' + ${s.eval} + '\u5ea6\u306f ' + ${s.percent} + '%\u3067\u3059\uff01\uff01\uff01'&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>CSS\u3092\u4f7f\u3063\u3066\u307f\u308b\u3002<\/p>\n<p>SpringBoot\u306e\u5834\u5408\u306f\u3001CSS\u30d5\u30a1\u30a4\u30eb\u3092src\/main\/resources \u306e\u4e0b\u306e static \u5185\u306b\u7f6e\u304f\u3002<\/p>\n<p>styles.css<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n@charset &quot;UTF-8&quot;;\r\n\r\nheader {\r\n\ttext-align: center;\r\n\tbackground: lightblue;\r\n}\r\n\r\nfooter {\r\n\ttext-align: center;\r\n\tbackground: lightblue;\r\n}\r\n<\/pre>\n<p>form.html \u306b\u30d8\u30c3\u30c0\u30fc\u3068\u30d5\u30c3\u30bf\u30fc\u3092\u8ffd\u52a0\u3059\u308b\u3002<br \/>\nhead\u8981\u7d20\u5185\u3067CSS\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u3002<\/p>\n<pre class=\"brush: xml; highlight: [6,10,11,12,35,36,37]; 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;\u8a3a\u65ad\u30da\u30fc\u30b8&lt;\/title&gt;\r\n&lt;link rel=&quot;stylesheet&quot; href=&quot;\/css\/styles.css&quot;&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;header&gt;\r\n\u3053\u306e\u90e8\u5206\u306f\u30d8\u30c3\u30c0\u30fc\u3067\u3059\u3088\r\n&lt;\/header&gt;\r\n\r\n&lt;h1&gt;\u8a3a\u65ad\u30da\u30fc\u30b8&lt;\/h1&gt;\r\n\r\n&lt;p th:text=&quot;${result}&quot;&gt;&lt;\/p&gt;\r\n\r\n&lt;form action=&quot;\/form&quot; method=&quot;post&quot;&gt;\r\n\t\u304a\u306a\u307e\u3048: &lt;input type=&quot;text&quot; name=&quot;name&quot; \/&gt;\r\n\t&lt;br \/&gt;\r\n\t\u8a3a\u65ad: &lt;input type=&quot;text&quot; name=&quot;eval&quot; \/&gt;\r\n\t&lt;input type=&quot;submit&quot; value=&quot;\u8a3a\u65ad&quot; \/&gt;\r\n&lt;\/form&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;h3&gt;\u3053\u308c\u307e\u3067\u306e\u8a3a\u65ad\u7d50\u679c&lt;\/h3&gt;\r\n&lt;table&gt;\r\n\t&lt;tr th:each=&quot;s : ${list}&quot;&gt;\r\n\t\t&lt;td th:text=&quot;${s.name} + ' \u3055\u3093\u306e ' + ${s.eval} + '\u5ea6\u306f ' + ${s.percent} + '%\u3067\u3059\uff01\uff01\uff01'&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n\r\n&lt;footer&gt;\r\n\u3053\u306e\u90e8\u5206\u306f\u30d5\u30c3\u30bf\u30fc\u3067\u3059\u3088\r\n&lt;\/footer&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\u5165\u529b\u30d5\u30a9\u30fc\u30e0\u90e8\u5206\u306a\u3069\u3092\u4e2d\u592e\u5bc4\u305b\u306b\u3059\u308b\u3002<\/p>\n<p>form.html<\/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;\u8a3a\u65ad\u30da\u30fc\u30b8&lt;\/title&gt;\r\n&lt;link rel=&quot;stylesheet&quot; href=&quot;\/css\/styles.css&quot;&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;header&gt;\r\n\u3053\u306e\u90e8\u5206\u306f\u30d8\u30c3\u30c0\u30fc\u3067\u3059\u3088\r\n&lt;\/header&gt;\r\n\r\n&lt;h1&gt;\u8a3a\u65ad\u30da\u30fc\u30b8&lt;\/h1&gt;\r\n\r\n&lt;p th:text=&quot;${result}&quot;&gt;&lt;\/p&gt;\r\n\r\n&lt;form action=&quot;\/form&quot; method=&quot;post&quot;&gt;\r\n\t&lt;div&gt;\u304a\u306a\u307e\u3048&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;\u306a\u306b\u5ea6\u3092\u8a3a\u65ad\u3057\u307e\u3059\u304b\uff1f&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input type=&quot;text&quot; name=&quot;eval&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;\u8a3a\u65ad&quot; \/&gt;&lt;\/div&gt;\r\n&lt;\/form&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;h3&gt;\u3053\u308c\u307e\u3067\u306e\u8a3a\u65ad\u7d50\u679c&lt;\/h3&gt;\r\n&lt;table&gt;\r\n\t&lt;tr th:each=&quot;s : ${list}&quot;&gt;\r\n\t\t&lt;td th:text=&quot;${s.name} + ' \u3055\u3093\u306e ' + ${s.eval} + '\u5ea6\u306f ' + ${s.percent} + '%\u3067\u3059\uff01\uff01\uff01'&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n\r\n&lt;footer&gt;\r\n\u3053\u306e\u90e8\u5206\u306f\u30d5\u30c3\u30bf\u30fc\u3067\u3059\u3088\r\n&lt;\/footer&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>styles.css<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n@charset &quot;UTF-8&quot;;\r\n\r\nheader {\r\n\ttext-align: center;\r\n\tbackground: #ffc107;\r\n\tcolor: white;\r\n}\r\n\r\nh1 {\r\n\ttext-align: center;\r\n\tcolor: darkblue;\r\n}\r\n\r\nform {\r\n\ttext-align: center;\r\n}\r\n\r\nfooter {\r\n\ttext-align: center;\r\n\tbackground: #ffc107;\r\n\tcolor: white;\r\n}\r\n\r\n#submit {\r\n\tbackground: lightgray;\r\n\tborder: outset;\r\n}\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>Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8d77\u52d5\u3059\u308b\u305f\u3073\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u521d\u671f\u5316\u3055\u308c\u3066\u3057\u307e\u3046\u8a2d\u5b9a\u306b\u306a\u3063\u3066\u3044\u305f\u306e\u3067\u3001\u305d\u308c\u3092\u4fee\u6b63\u3059\u308b\u3002 application.properties spring.datasource.url=jdbc:hsqld &hellip; <a href=\"https:\/\/kpc2020.satoshis.jp\/?p=71\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Spring Boot\u3092\u4f7f\u3063\u3066Web\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3059\u308b \u305d\u306e3<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[],"class_list":["post-71","post","type-post","status-publish","format-standard","hentry","category-java","category-springboot"],"views":199,"_links":{"self":[{"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/71","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=71"}],"version-history":[{"count":7,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":78,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/71\/revisions\/78"}],"wp:attachment":[{"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}