{"id":2906,"date":"2018-05-19T15:48:40","date_gmt":"2018-05-19T06:48:40","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=2906"},"modified":"2023-05-27T23:10:03","modified_gmt":"2023-05-27T14:10:03","slug":"%e3%80%90spring-boot%e3%80%91jsp%e3%81%a7%e3%83%93%e3%83%a5%e3%83%bc%e3%82%92%e4%bd%9c%e3%82%8d%e3%81%86%e3%80%82","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=2906","title":{"rendered":"\u3010Spring Boot\u3011\u300cThymeleaf(\u30bf\u30a4\u30e0\u30ea\u30fc\u30d5)\u300d\u3067\u30d3\u30e5\u30fc\u3092\u4f5c\u308d\u3046\u3002(Hello World)"},"content":{"rendered":"<p>Spring Boot\u3067\u306f\u3001\u300cThymeleaf(\u30bf\u30a4\u30e0\u30ea\u30fc\u30d5)\u300d\u3068\u3044\u3046\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3067\u30d3\u30e5\u30fc\u3092\u4f5c\u308b\u306e\u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>JSP\u3067\u4f5c\u3089\u306a\u3044\u306e\u304b\uff1f<\/h2>\n<p>Java\u3067\u306eWeb\u958b\u767a\u306b\u306a\u308c\u3066\u3044\u308b\u65b9\u3067\u3042\u308c\u3070\u3001\u8ab0\u3057\u3082\u30d3\u30e5\u30fc\u3068\u3044\u3048\u3070\u3001<span style=\"color: #ff0000;\"><strong>\u300cJSP\u300d<\/strong><\/span>\u3068\u3044\u3046\u30a4\u30e1\u30fc\u30b8\u304c\u3042\u308b\u65b9\u304c\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001Spring Boot(\u7279\u306b\u30011.2\u4ee5\u964d\uff09\u306f\u3001<span style=\"color: #ff0000;\"><strong>JSP\u306e\u5229\u7528\u3092\u63a8\u5968\u3057\u3066\u304a\u3089\u305a\u3001<\/strong><span style=\"color: #000000;\">\u300cThymeleaf\u300d\u7b49\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3092\u4f7f\u3046\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/span><\/span><\/p>\n<h2>\u300cThymeleaf(\u30bf\u30a4\u30e0\u30ea\u30fc\u30d5)\u300d\u3067\u30d3\u30e5\u30fc\u3092\u4f5c\u308b\u3002<\/h2>\n<p>\u305d\u308c\u3067\u306f\u3001\u5b9f\u969b\u306b\u3001\u300cThymeleaf\u300d\u3067\u30d3\u30e5\u30fc\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u300cThymeleaf(\u30bf\u30a4\u30e0\u30ea\u30fc\u30d5)\u300d\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>\u307e\u305a\u306f\u3001pom.xml\u306b\u5bfe\u3057\u3066\u3001\u4e0b\u8a18\u306e\u8a18\u8ff0\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;dependency&gt;\r\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;\/artifactId&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>\u3053\u308c\u304c\u3001\u300cThymeleaf\u300d\u306e\u300cdependency\u300d\u306b\u3042\u305f\u308a\u307e\u3059\u3002<\/p>\n<h3>\u300cThymeleaf\u300d\u3067\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308b\u3002<\/h3>\n<p>\u305d\u308c\u3067\u306f\u3001\u30d3\u30e5\u30fc\u306e\u5143\u3068\u306a\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4>SpringController.java(\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\uff09<\/h4>\n<pre class=\"lang:default decode:true\">package com.example.demo;\r\n\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.ui.Model;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\n\r\n@Controller\r\npublic class SpringController {\r\n\r\n    @RequestMapping(\"\/hello\")\r\n    public String hello(Model model) {\r\n        model.addAttribute(\"helloworld\", \"Hello World\");\r\n        return \"hello\";\r\n    }\r\n}<\/pre>\n<p><strong>\u5f15\u6570\u306eModel<\/strong><\/p>\n<p>Model\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3068\u3001\u30d3\u30e5\u30fc\u306e\u9593\u3067\u5024\u3092\u5171\u6709\u3059\u308b\u305f\u3081\u306e\u30af\u30e9\u30b9<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<p>\u5f79\u5272\u3068\u3057\u3066\u306f\u3001<span style=\"color: #ff0000;\"><strong>JSP\/Servlet\u3067\u8a00\u3048\u3070\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u3068\u540c\u3058<\/strong><\/span>\u3067\u3059\u306d\u3002<\/p>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30e2\u30c7\u30eb\u306b\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30d3\u30e5\u30fc\u3067\u305d\u306e\u5909\u6570\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u30e2\u30c7\u30eb\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9.addAttribute(\"\u5909\u6570\u540d\", \"\u5024\");<\/pre>\n<p>\u307e\u305f\u3001\u30e1\u30bd\u30c3\u30c9\u306e\u623b\u308a\u5024\u3067String\u306e\u6587\u5b57\u5217\u3092\u8fd4\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u306e\u6587\u5b57\u5217\u3092\u300cmain\/resources\/templates\/(\u6587\u5b57\u5217).html\u300d\u3068\u3044\u3046\u5f62\u3067\u691c\u7d22\u3057\u307e\u3059\u3002<\/p>\n<h4>hello.html(\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\uff09<\/h4>\n<pre class=\"lang:default decode:true\">&lt;!DOCTYPE HTML&gt;\r\n&lt;html xmlns:th=\"http:\/\/www.thymeleaf.org\"&gt;\r\n&lt;head&gt;\r\n    &lt;title&gt;Hello World!&lt;\/title&gt;\r\n    &lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=UTF-8\" \/&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;p th:text=\"${helloworld}\" \/&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3053\u308c\u304c\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u306a\u308a\u307e\u3059\u3002JSP\u3067\u306f\u306a\u304f\u3001HTML\u30d5\u30a1\u30a4\u30eb\u306b\u306a\u308a\u307e\u3057\u305f\u306d\u3002<\/p>\n<p>\u300cmain\/resources\/templates\u300d\u306e\u4e0b\u306b\u914d\u7f6e\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2925\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u914d\u7f6e.png\" alt=\"\" width=\"161\" height=\"114\" \/><\/p>\n<p><strong>th:text<\/strong><\/p>\n<p>\u3053\u308c\u306f\u3001\u300cThymeleaf(\u30bf\u30a4\u30e0\u30ea\u30fc\u30d5)\u300d\u7528\u306e\u5c5e\u6027\u3067\u3059\u3002<\/p>\n<p>p\u30bf\u30b0\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3067\u3001\u4e0b\u8a18\u306e\u5909\u63db\u304c\u884c\u308f\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;p th:text=\"${helloworld}\" \/&gt;<\/pre>\n<p>\u2193\u2193\u2193<\/p>\n<pre class=\"lang:default decode:true\">&lt;p&gt;\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u304b\u3089\u53d7\u3051\u308b\u5909\u6570&lt;\/p&gt;<\/pre>\n<h4>\u5b9f\u884c\u7d50\u679c<\/h4>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2922\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/hello-world_ThemaReaf.png\" alt=\"\" width=\"283\" height=\"101\" \/><\/p>\n<h2>ModelAndView\u3067\u30bd\u30fc\u30b9\u3092\u66f8\u304d\u76f4\u3059\u3002<\/h2>\n<p>\u5148\u307b\u3069\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u3001Model\u3092\u4f7f\u3063\u3066\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3068\u30d3\u30e5\u30fc\u3067\u5024\u3092\u5171\u6709\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u4eca\u5ea6\u306f\u3001ModelAndView\u3068\u3044\u3046\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u3082\u540c\u3058\u3088\u3046\u306b\u5b9f\u88c5\u3067\u304d\u308b\u306e\u3067\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>HTML\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u90e8\u5206\u306f\u540c\u3058\u3067\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3060\u3051\u4e0b\u8a18\u306e\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">package com.example.demo;\r\n\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.servlet.ModelAndView;\r\n\r\n@Controller\r\npublic class SpringController {\r\n\r\n    @RequestMapping(\"\/hello\")\r\n    public ModelAndView hello(ModelAndView mav) {\r\n    \tmav.setViewName(\"hello\");\r\n    \tmav.addObject(\"helloworld\", \"Hello World!(ModelAndView\u3088\u308a)\");\r\n        return mav;\r\n    }\r\n}\r\n\r\n<\/pre>\n<h3>setViewName\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u3053\u3053\u306b\u5165\u308c\u305f\u5024\u304c\u3001<span style=\"color: #ff0000;\"><strong>\u300cmain\/resources\/templates\/(\u6587\u5b57\u5217).html\u300d\u3067\u63a2\u3057\u306b\u884c\u304f\u6587\u5b57\u5217\u306b\u8a72\u5f53<\/strong><\/span>\u3057\u307e\u3059\u3002<\/p>\n<h3>addObject\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u3053\u308c\u3067\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3068\u30d3\u30e5\u30fc\u3067\u5171\u6709\u3059\u308b\u5909\u6570\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p><strong>Model<\/strong>\u3068\u540c\u3058\u3088\u3046\u306b\u66f8\u304f\u306e\u3067\u3042\u3063\u3066\u3082\u3001<strong>ModelAndView<\/strong>\u3067\u66f8\u3044\u305f\u307b\u3046\u304c\u3001\u30e1\u30bd\u30c3\u30c9\u306e\u69cb\u9020\u3068\u3057\u3066\u306f\u30b9\u30c3\u30ad\u30ea\u3057\u307e\u3059\u3088\u306d\u3002<\/p>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2930\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/\u5b9f\u884c\u7d50\u679c\uff08ModelAndView.png\" alt=\"\" width=\"305\" height=\"111\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/\u5b9f\u884c\u7d50\u679c\uff08ModelAndView.png 305w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/\u5b9f\u884c\u7d50\u679c\uff08ModelAndView-300x109.png 300w\" sizes=\"(max-width: 305px) 100vw, 305px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"Spring Boot\u3067\u306f\u3001\u300cThymeleaf(\u30bf\u30a4\u30e0\u30ea\u30fc\u30d5)\u300d\u3068\u3044\u3046\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3067\u30d3\u30e5\u30fc\u3092\u4f5c\u308b\u306e\u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u307e\u3059\u3002 JSP\u3067\u4f5c\u3089\u306a\u3044\u306e\u304b\uff1f Java\u3067\u306eWeb\u958b\u767a\u306b\u306a\u308c\u3066\u3044\u308b\u65b9\u3067\u3042\u308c\u3070\u3001\u8ab0\u3057\u3082\u30d3\u30e5\u30fc\u3068\u3044\u3048\u3070 [&hellip;]","protected":false},"author":1,"featured_media":2468,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2906"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2906"}],"version-history":[{"count":13,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2906\/revisions"}],"predecessor-version":[{"id":20569,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2906\/revisions\/20569"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/2468"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2906"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}