{"id":3052,"date":"2018-05-20T15:57:48","date_gmt":"2018-05-20T06:57:48","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=3052"},"modified":"2023-05-27T23:08:52","modified_gmt":"2023-05-27T14:08:52","slug":"%e3%80%90spring-mvc%e3%80%91%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab%e3%83%97%e3%83%ad%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88%e3%82%92%e4%bd%9c%e6%88%90%e3%81%97%e3%82%88%e3%81%86%e3%80%82","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=3052","title":{"rendered":"\u3010Spring MVC\u3011\u30b5\u30f3\u30d7\u30eb\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3057\u3088\u3046\u3002(HelloWorld\uff09"},"content":{"rendered":"<p>\u305d\u308c\u3067\u306f\u3001Spring MVC\u3067\u3001\u30b5\u30f3\u30d7\u30eb\u7684\u306aWeb\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u305d\u306e\u524d\u306b\u3001\u3069\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u3069\u306e\u3088\u3046\u306a\u30d5\u30a1\u30a4\u30eb\u3092\u914d\u7f6e\u3059\u308c\u3070\u3088\u3044\u306e\u304b\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30c7\u30a3\u30ec\u30af\u30c8\u69cb\u9020<\/h2>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3055\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/Spring-MVC\u56f3.png\" alt=\"\" width=\"443\" height=\"484\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/Spring-MVC\u56f3.png 443w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/Spring-MVC\u56f3-275x300.png 275w\" sizes=\"(max-width: 443px) 100vw, 443px\" \/><\/p>\n<table>\n<tbody>\n<tr>\n<th>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>src\/main\/java<\/td>\n<td>\u30e2\u30c7\u30eb\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u914d\u7f6e\u3057\u307e\u3059\u3002\uff08\u30d1\u30c3\u30b1\u30fc\u30b8\u69cb\u6210\u306f\u81ea\u7531\u3067\u3059\u3002\uff09<\/td>\n<\/tr>\n<tr>\n<td>src\/main\/webapp<\/td>\n<td>Spring MVC\u306eWeb\u30a2\u30d7\u30ea\u306e\u672c\u4f53\u3067\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>src\/main\/webapp\/view<\/td>\n<td>\u3053\u3053\u306b\u3001\u30d3\u30e5\u30fc\u3067\u3042\u308bjsp\u3092\u914d\u7f6e\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u30b5\u30f3\u30d7\u30eb\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3002<\/h2>\n<p>Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u3044\u3048\u3070\u3001\u307e\u305a\u306f\u300c\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u300d\u3067\u3059\u3088\u306d\u3002\u307e\u305a\u306f\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u300csrc\/main\/java\u300d\u30d5\u30a9\u30eb\u30c0\u306b\u3066\u3001\u300c\u53f3\u30af\u30ea\u30c3\u30af\u300d\u2192\u300c\u65b0\u898f\u300d\u2192\u300c\u30af\u30e9\u30b9\u300d\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3058\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/mvc\u30b5\u30f3\u30d7\u30eb\uff11.png\" alt=\"\" width=\"526\" height=\"252\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/mvc\u30b5\u30f3\u30d7\u30eb\uff11.png 526w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/mvc\u30b5\u30f3\u30d7\u30eb\uff11-300x144.png 300w\" sizes=\"(max-width: 526px) 100vw, 526px\" \/><\/p>\n<p>\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u3001\u30af\u30e9\u30b9\u540d\u3092\u5165\u529b\u3057\u3066\u3001\u300c\u5b8c\u4e86\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3059\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/mvc\u30b5\u30f3\u30d7\u30eb\uff12.png\" alt=\"\" width=\"595\" height=\"538\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/mvc\u30b5\u30f3\u30d7\u30eb\uff12.png 595w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/mvc\u30b5\u30f3\u30d7\u30eb\uff12-300x271.png 300w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/p>\n<h3>MvcController.java(\u4f5c\u6210\u3057\u305f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067\u3059\u3002\uff09<\/h3>\n<pre class=\"lang:default decode:true\">package mvcapp;\r\n\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.ui.Model;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\n\r\n@Controller\r\npublic class MvcController {\r\n\r\n\t@RequestMapping(value = \"\/helloWorld\",method = RequestMethod.GET)\r\n\tpublic String helloWorld(Model model) {\r\n\t\tmodel.addAttribute(\"message\", \"Hello World!\");\r\n\t\treturn \"showMessage\";\r\n\t}\r\n\r\n}<\/pre>\n<h4>\u4f7f\u3063\u3066\u3044\u308b\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3<\/h4>\n<table>\n<tbody>\n<tr>\n<th>\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>@Controller<\/td>\n<td><span style=\"color: #ff0000;\"><strong>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30af\u30e9\u30b9<\/strong><\/span>\u3067\u3042\u308b\u3053\u3068\u3092\u8868\u3057\u307e\u3059\u3002\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4f5c\u308b\u969b\u306f\u5fc5\u305a\u6307\u5b9a\u3057\u307e\u3057\u3087\u3046\u3002<\/td>\n<\/tr>\n<tr>\n<td>@RequestMapping<\/td>\n<td><span style=\"color: #ff0000;\"><strong>\u300c\u30ea\u30af\u30a8\u30b9\u30c8\u30de\u30c3\u30d4\u30f3\u30b0\u300d<\/strong><\/span>\u3092\u6307\u5b9a\u3059\u308b\u305f\u3081\u306e\u3082\u306e\u3067\u3059\u3002\uff08\u8981\u306f\u3001\u300c\/helloWorld\u300d\u3068\u3044\u3046\uff35\uff32\uff2c\u3068\u3001\u3053\u3053\u3067\u4f5c\u3063\u305f\u30e1\u30bd\u30c3\u30c9\u3092\u7d10\u3065\u3051\u3066\u3044\u307e\u3059\u3002\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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\/main\/webapp\/WEB-INF\/view\/(\u6587\u5b57\u5217).jsp\u300d\u3068\u3044\u3046\u5f62\u3067JSP\u30d5\u30a1\u30a4\u30eb\u3092\u691c\u7d22\u3057\u307e\u3059\u3002<\/p>\n<h4>\u00a0showMessage.jsp(\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u3082\u5b58\u5728\u3059\u308bJSP\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002\uff09<\/h4>\n<pre class=\"lang:default decode:true\">&lt;!DOCTYPE html&gt;\r\n\r\n&lt;%@ page language=\"java\" contentType=\"text\/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%&gt;\r\n    \r\n&lt;html&gt;\r\n\t&lt;head&gt;\r\n\t\t&lt;meta charset=\"utf-8\"&gt;\r\n\t\t&lt;title&gt;Welcome&lt;\/title&gt;\r\n\t&lt;\/head&gt; \r\n\t&lt;body&gt;\r\n\t\t&lt;h2&gt;${message}&lt;\/h2&gt;\r\n\t&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>Spring MVC\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u305f\u969b\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u5b58\u5728\u3059\u308bJSP\u3092\u305d\u306e\u307e\u307e\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u300c${message}\u300d\u306e\u90e8\u5206\u304c\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3068\u3084\u308a\u3068\u308a\u3059\u308bModel\u5909\u6570\u3092\u793a\u3057\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h3>mvc-config.xml<\/h3>\n<pre class=\"lang:default decode:true\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n\r\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txmlns:mvc=\"http:\/\/www.springframework.org\/schema\/mvc\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\r\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/mvc http:\/\/www.springframework.org\/schema\/mvc\/spring-mvc.xsd\r\n\t\thttp:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\r\n\t\thttp:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd\"&gt;\r\n\r\n    &lt;context:component-scan base-package=\"mvcapp\"\/&gt;\r\n\r\n    &lt;mvc:annotation-driven \/&gt;\r\n\r\n\t&lt;bean class=\"org.springframework.web.servlet.view.InternalResourceViewResolver\"&gt;\r\n\t        &lt;!-- Example: a logical view name of 'showMessage' is mapped to '\/WEB-INF\/jsp\/showMessage.jsp' --&gt;\r\n\t        &lt;property name=\"prefix\" value=\"\/WEB-INF\/view\/\"\/&gt;\r\n\t        &lt;property name=\"suffix\" value=\".jsp\"\/&gt;\r\n\t&lt;\/bean&gt;\r\n\r\n&lt;\/beans&gt;<\/pre>\n<p>Spring MVC\u3067\u306f\u3001\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u305f\u3089\u3001\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u767b\u9332\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u5143\u3005\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u8a18\u8ff0\u304c\u3042\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3092\u5916\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:default decode:true\">    &lt;!-- Uncomment and your base-package here:\r\n         &lt;context:component-scan\r\n            base-package=\"org.springframework.samples.web\"\/&gt;  --&gt;<\/pre>\n<p>base-package\u3068\u3044\u3046\u306b\u3066\u3001\u4f5c\u6210\u3057\u305f\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u305d\u3046\u3059\u308b\u3068\u3001<span style=\"color: #ff0000;\"><strong>\u3053\u3053\u3067\u6307\u5b9a\u3057\u305f\u30d1\u30c3\u30b1\u30fc\u30b8\u304b\u3089 \u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u691c\u7d22\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h3>\u30d7\u30ed\u30b0\u30e9\u30e0\u4f5c\u6210\u5f8c\u306e\u914d\u7f6e<\/h3>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u4f5c\u6210\u5f8c\u306f\u3001\u4e0b\u8a18\u306e\u914d\u7f6e\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3060\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/\u914d\u7f6e\u5f8c\u306e\u69cb\u6210.png\" alt=\"\" width=\"568\" height=\"344\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/\u914d\u7f6e\u5f8c\u306e\u69cb\u6210.png 568w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/\u914d\u7f6e\u5f8c\u306e\u69cb\u6210-300x182.png 300w\" sizes=\"(max-width: 568px) 100vw, 568px\" \/><\/p>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3061\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/mvc_\u5b9f\u884c\u7d50\u679c.png\" alt=\"\" width=\"394\" height=\"135\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/mvc_\u5b9f\u884c\u7d50\u679c.png 394w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/mvc_\u5b9f\u884c\u7d50\u679c-300x103.png 300w\" sizes=\"(max-width: 394px) 100vw, 394px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"\u305d\u308c\u3067\u306f\u3001Spring MVC\u3067\u3001\u30b5\u30f3\u30d7\u30eb\u7684\u306aWeb\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002 \u305d\u306e\u524d\u306b\u3001\u3069\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u3069\u306e\u3088\u3046\u306a\u30d5\u30a1\u30a4\u30eb\u3092\u914d\u7f6e\u3059\u308c\u3070\u3088\u3044\u306e\u304b\u89e3\u8aac\u3057\u307e\u3059\u3002 \u30c7\u30a3\u30ec\u30af\u30c8\u69cb\u9020 \u30c7\u30a3\u30ec\u30af\u30c8\u30ea \u8aac\u660e src\/main\/jav [&hellip;]","protected":false},"author":1,"featured_media":2543,"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\/3052"}],"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=3052"}],"version-history":[{"count":8,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/3052\/revisions"}],"predecessor-version":[{"id":20565,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/3052\/revisions\/20565"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/2543"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3052"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}