{"id":107,"date":"2019-05-31T10:02:47","date_gmt":"2019-05-31T01:02:47","guid":{"rendered":"http:\/\/2019se3.satoshis.jp\/?p=107"},"modified":"2019-05-31T12:25:06","modified_gmt":"2019-05-31T03:25:06","slug":"5%e6%9c%8831%e6%97%a5","status":"publish","type":"post","link":"https:\/\/2019se3.satoshis.jp\/?p=107","title":{"rendered":"5\u670831\u65e5"},"content":{"rendered":"<h3>URL\u306e\u69cb\u6210<\/h3>\n<p>http:\/\/hostname:port\/contextpath\/path?querystring<\/p>\n<h3>Spring Boot \u3067 Hello World<\/h3>\n<p>HeloController.java<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.abc;\r\n\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@RestController\r\npublic class HeloController {\r\n\r\n\t@RequestMapping(&quot;\/&quot;)\r\n\tpublic String index() {\r\n\t\treturn &quot;Hello Spring Boot World!&quot;;\r\n\t}\r\n}\r\n<\/pre>\n<p>@RequestMapping\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u3044\u308d\u3044\u308d\u306aURL\u30d1\u30b9\u306b\u5bfe\u5fdc\u3059\u308b\u6a5f\u80fd\u3092\u8ffd\u52a0\u3067\u304d\u308b\u3002<\/p>\n<p>HeloController.java \u306b\u4ee5\u4e0b\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002<br \/>\n<a href=\"http:\/\/localhost:8080\/hello\">http:\/\/localhost:8080\/hello<\/a><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(&quot;\/hello&quot;)\r\n\tpublic String hello() {\r\n\t\treturn &quot;Hello World! - path = \/hello&quot;;\r\n\t}\r\n<\/pre>\n<h3>\u30d1\u30b9\u5909\u6570<\/h3>\n<p>URL\u30d1\u30b9\u306b\u5909\u6570\u3092\u542b\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<br \/>\n@PathVariable \u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n<p><a href=\"http:\/\/localhost:8080\/sum\/123\">http:\/\/localhost:8080\/sum\/123<\/a><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(&quot;\/sum\/{num}&quot;)\r\n\tpublic String sum(@PathVariable int num) {\r\n\t\tint res = 0;\r\n\t\tfor (int i = 1; i &lt;= num; i++) {\r\n\t\t\tres += i;\r\n\t\t}\r\n\t\treturn &quot;total: &quot; + res;\r\n\t}\r\n<\/pre>\n<h3>JSON\u3092\u51fa\u529b\u3059\u308b<\/h3>\n<p>\u30c6\u30ad\u30b9\u30c8\u3067\u306fDataObject\u30af\u30e9\u30b9\u3092\u540c\u4e00\u30bd\u30fc\u30b9\u5185\u306b\u66f8\u3044\u3066\u3044\u308b\u304c\u597d\u307e\u3057\u304f\u306a\u3044\u306e\u3067\u3001\u5225\u306e\u30af\u30e9\u30b9\u3068\u3057\u3066\u65b0\u898f\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.abc;\r\n\r\npublic class DataObject {\r\n\tprivate int id;\r\n\tprivate String name;\r\n\tprivate String value;\r\n\r\n\tpublic DataObject(int id, String name, String value) {\r\n\t\tthis.id = id;\r\n\t\tthis.name = name;\r\n\t\tthis.value = value;\r\n\t}\r\n\r\n\tpublic int getId() {\r\n\t\treturn id;\r\n\t}\r\n\tpublic void setId(int id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\tpublic String getValue() {\r\n\t\treturn value;\r\n\t}\r\n\tpublic void setValue(String value) {\r\n\t\tthis.value = value;\r\n\t}\r\n}\r\n<\/pre>\n<p>HeloController\u306b\u4ee5\u4e0b\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3068\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\tString[] names = { &quot;tsuyano&quot;, &quot;hanako&quot;, &quot;taro&quot;,\r\n\t\t\t\t\t   &quot;sachiko&quot;, &quot;ichiro&quot; };\r\n\tString[] mails = {\r\n\t\t\t&quot;syoda@tsuyano.com&quot;,\r\n\t\t\t&quot;hanako@flower&quot;,\r\n\t\t\t&quot;taro@yamada&quot;,\r\n\t\t\t&quot;sachiko@happy&quot;,\r\n\t\t\t&quot;ichiro@baseball&quot;\r\n\t};\r\n\r\n\t@RequestMapping(&quot;\/users\/{id}&quot;)\r\n\tpublic DataObject users(@PathVariable int id) {\r\n\t\treturn new DataObject(id, names[id], mails[id]);\r\n\t}\r\n<\/pre>\n<h3>Thymeleaf\u3092\u4f7f\u3063\u3066Web\u30b5\u30a4\u30c8\u3092\u4f5c\u308b<\/h3>\n<p>Thymeleaf\u3092\u4f7f\u3046\u306b\u306f\u3001\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<br \/>\npom.xml \u306b\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; highlight: [33,34,35,36]; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\r\n&lt;project xmlns=&quot;http:\/\/maven.apache.org\/POM\/4.0.0&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\r\n\txsi:schemaLocation=&quot;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd&quot;&gt;\r\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n\t&lt;parent&gt;\r\n\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n\t\t&lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\r\n\t\t&lt;version&gt;2.1.4.RELEASE&lt;\/version&gt;\r\n\t\t&lt;relativePath\/&gt; &lt;!-- lookup parent from repository --&gt;\r\n\t&lt;\/parent&gt;\r\n\t&lt;groupId&gt;jp.abc&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;MyBootApp&lt;\/artifactId&gt;\r\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\r\n\t&lt;name&gt;MyBootApp&lt;\/name&gt;\r\n\t&lt;description&gt;Demo project for Spring Boot&lt;\/description&gt;\r\n\r\n\t&lt;properties&gt;\r\n\t\t&lt;java.version&gt;1.8&lt;\/java.version&gt;\r\n\t&lt;\/properties&gt;\r\n\r\n\t&lt;dependencies&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;\r\n\t\t\t&lt;scope&gt;test&lt;\/scope&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;\/artifactId&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t&lt;\/dependencies&gt;\r\n\r\n\t&lt;build&gt;\r\n\t\t&lt;plugins&gt;\r\n\t\t\t&lt;plugin&gt;\r\n\t\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n\t\t\t\t&lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt;\r\n\t\t\t&lt;\/plugin&gt;\r\n\t\t&lt;\/plugins&gt;\r\n\t&lt;\/build&gt;\r\n\r\n&lt;\/project&gt;\r\n<\/pre>\n<p>[Maven]-[\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u66f4\u65b0]\u3068[\u5b9f\u884c]-[maven install]\u3092\u5b9f\u65bd\u3059\u308b\u3002<\/p>\n<p>\u30c6\u30ad\u30b9\u30c8\u3067\u306fHeloController\u3092\u4fee\u6b63\u3057\u3066\u3044\u308b\u304c\u3001\u3053\u3053\u3067\u306f\u65b0\u898f\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>IndexController.java<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.abc;\r\n\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\n\r\n@Controller\r\npublic class IndexController {\r\n\r\n\t@RequestMapping(&quot;\/index&quot;)\r\n\tpublic String index() {\r\n\t\treturn &quot;index&quot;;\r\n\t}\r\n}\r\n<\/pre>\n<p>HTML\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\nsrc\/main\/resources\/templates \u3092\u53f3\u30af\u30ea\u30c3\u30af\u3057\u3066\u65b0\u898f\u4f5c\u6210\u3067HTML\u30d5\u30a1\u30a4\u30eb\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;top page&lt;\/title&gt;\r\n&lt;style type=&quot;text\/css&quot;&gt;\r\n\th1 {\r\n\t\tfont-size: 18pt;\r\n\t\tfont-weight: bold;\r\n\t\tcolor: gray;\r\n\t}\r\n\tbody {\r\n\t\tfont-size: 13pt;\r\n\t\tcolor: gray;\r\n\t\tmargin: 5px 25px;\r\n\t}\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h1&gt;helo page&lt;\/h1&gt;\r\n&lt;p class=&quot;msg&quot;&gt;this is Thymeleaf sample page&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u5024\u3092\u8868\u793a\u3059\u308b<\/strong><\/p>\n<pre class=\"brush: xml; first-line: 19; highlight: [23]; title: ; notranslate\" title=\"\">\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;helo page&lt;\/h1&gt;\r\n&lt;p class=&quot;msg&quot;&gt;this is Thymeleaf sample page&lt;\/p&gt;\r\n&lt;p class=&quot;msg&quot; th:text=&quot;${msg}&quot;&gt;&lt;\/p&gt;\r\n\r\n&lt;\/body&gt;\r\n<\/pre>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067\u306f\u5f15\u6570\u306bModel\u3092\u8ffd\u52a0\u3059\u308b\u3002<br \/>\nModel\u3092\u901a\u3057\u3066\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u5024\u3092\u6e21\u3059\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.abc;\r\n\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.ui.Model;\r\nimport org.springframework.web.bind.annotation.PathVariable;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\n\r\n@Controller\r\npublic class IndexController {\r\n\r\n\t@RequestMapping(&quot;\/index\/{num}&quot;)\r\n\tpublic String index(@PathVariable int num, Model model) {\r\n\t\tint res = 0;\r\n\t\tfor (int i = 1; i &lt;= num; i++) {\r\n\t\t\tres += i;\r\n\t\t}\r\n\t\tmodel.addAttribute(&quot;msg&quot;, &quot;total: &quot; + res);\r\n\t\treturn &quot;index&quot;;\r\n\t}\r\n}\r\n<\/pre>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>URL\u306e\u69cb\u6210 http:\/\/hostname:port\/contextpath\/path?querystring Spring Boot \u3067 Hello World HeloController.java @Reques &hellip; <a href=\"https:\/\/2019se3.satoshis.jp\/?p=107\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;5\u670831\u65e5&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,3],"tags":[],"_links":{"self":[{"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/107"}],"collection":[{"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=107"}],"version-history":[{"count":7,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":114,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions\/114"}],"wp:attachment":[{"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}