
{"id":2671,"date":"2020-12-12T11:03:56","date_gmt":"2020-12-12T03:03:56","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2671"},"modified":"2021-01-01T14:36:55","modified_gmt":"2021-01-01T06:36:55","slug":"2020java%e6%a1%86%e6%9e%b6%e6%95%99%e7%a8%8b%e4%b9%8bspringmvc%e5%88%9b%e5%bb%bamaven%e9%a1%b9%e7%9b%ae","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2671","title":{"rendered":"2020java\u6846\u67b6\u6559\u7a0b\u4e4bspringMVC\u521b\u5efamaven\u9879\u76ee"},"content":{"rendered":"<h3>2020java\u6846\u67b6\u6559\u7a0b\u4e4bspringMVC\u521b\u5efamaven\u9879\u76ee<\/h3>\n<p><strong>1.\u521b\u5efaweb\u9879\u76ee<\/strong><\/p>\n<p><strong>2.\u5bfc\u5165\u4f9d\u8d56<\/strong><\/p>\n<pre>&lt;dependencies&gt;\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;spring-webmvc&lt;\/artifactId&gt;\r\n        &lt;version&gt;4.2.8.RELEASE&lt;\/version&gt;\r\n    &lt;\/dependency&gt;\r\n&lt;\/dependencies&gt;<\/pre>\n<p><strong>\u7136\u540e\u70b9\u51fb\u53f3\u4fa7\u7684maven\uff0c\u7136\u540e\u5237\u65b0\u5373\u53ef\u81ea\u52a8\u5bfc\u5165\u4f9d\u8d56<\/p>\n<p><\/strong><!--more--><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/12\/2.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u7136\u540e\u5de6\u4fa7\u9879\u76ee\u7ed3\u6784\u5c31\u4f1a\u51fa\u73b0\u76f8\u5173jar\u5305<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/12\/1.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>3.\u4fee\u6539web.xml\u6587\u4ef6<\/strong><\/p>\n<pre>&lt;!-- servlet\u914d\u7f6e --&gt;\r\n&lt;servlet&gt;\r\n  &lt;servlet-name&gt;springMVC&lt;\/servlet-name&gt;\r\n  &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;\/servlet-class&gt;\r\n  &lt;!-- springmvc\u914d\u7f6e\u6587\u4ef6\u9ed8\u8ba4\u7684\u540d\u5b57 springMVC-servlet.xml  --&gt;\r\n  &lt;init-param&gt;\r\n    &lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;\r\n    &lt;param-value&gt;classpath:springMVC-servlet.xml&lt;\/param-value&gt;\r\n  &lt;\/init-param&gt;\r\n  &lt;load-on-startup&gt;1&lt;\/load-on-startup&gt;\r\n&lt;\/servlet&gt;\r\n&lt;servlet-mapping&gt;\r\n  &lt;servlet-name&gt;springMVC&lt;\/servlet-name&gt;\r\n  &lt;url-pattern&gt;\/&lt;\/url-pattern&gt;\r\n&lt;\/servlet-mapping&gt;\r\n&lt;!-- \u89e3\u51b3 SpringMVC\u7684 post \u4e71\u7801 --&gt;\r\n&lt;filter&gt;\r\n  &lt;filter-name&gt;requestContextFilter&lt;\/filter-name&gt;\r\n  &lt;filter-class&gt;org.springframework.web.filter.RequestContextFilter&lt;\/filter-class&gt;\r\n  &lt;init-param&gt;\r\n    &lt;param-name&gt;encoding&lt;\/param-name&gt;\r\n    &lt;param-value&gt;UTF-8&lt;\/param-value&gt;\r\n  &lt;\/init-param&gt;\r\n  &lt;init-param&gt;\r\n    &lt;param-name&gt;forceEncoding&lt;\/param-name&gt;\r\n    &lt;param-value&gt;true&lt;\/param-value&gt;\r\n  &lt;\/init-param&gt;\r\n&lt;\/filter&gt;\r\n&lt;filter-mapping&gt;\r\n  &lt;filter-name&gt;requestContextFilter&lt;\/filter-name&gt;\r\n  &lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n&lt;\/filter-mapping&gt;<\/pre>\n<p><strong>4.\u5728resource\u6587\u4ef6\u5939\u4e0b\u521b\u5efaspringMVC-servlet.xml<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n       xmlns:mvc=\"http:\/\/www.springframework.org\/schema\/mvc\"\r\n       xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\r\n       xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n       xsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans\r\n       http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\r\n       http:\/\/www.springframework.org\/schema\/context\r\n       http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd\r\n        http:\/\/www.springframework.org\/schema\/mvc\r\n        https:\/\/www.springframework.org\/schema\/mvc\/spring-mvc.xsd\"&gt;\r\n    &lt;mvc:annotation-driven enable-matrix-variables=\"true\"\/&gt;\r\n    &lt;!-- \u626b\u63cf controller  --&gt;\r\n    &lt;context:component-scan base-package=\"springmvc.controller\"\/&gt;\r\n    &lt;!-- \u89c6\u56fe\u89e3\u6790\u5668  --&gt;\r\n    &lt;bean id=\"jspViewResolver\" class=\"org.springframework.web.servlet.view.InternalResourceViewResolver\"&gt;\r\n        &lt;!--&lt;property name=\"viewClass\" value=\"org.springframework.web.servlet.view.JstlView\"\/&gt;--&gt;\r\n        &lt;property name=\"prefix\" value=\"\/WEB-INF\/jsp\/\"\/&gt;&lt;!-- \u524d\u7f00  --&gt;\r\n        &lt;property name=\"suffix\" value=\".jsp\"\/&gt;&lt;!-- \u540e\u7f00  --&gt;\r\n    &lt;\/bean&gt;\r\n&lt;\/beans&gt;<\/pre>\n<p><strong>5.\u5728WEB-INF\u4e0b\u521b\u5efajsp\u6587\u4ef6\u5939<\/strong><\/p>\n<p><strong>6.\u5728java\u5305\u4e0b\u521b\u5efacontroller\u5305\uff0c\u5199\u4e2a\u7c7b\uff0c\u8fd4\u56de\u8def\u5f84\u53c2\u6570<\/strong><\/p>\n<pre>@Controller\r\npublic class IndexController {\r\n    @RequestMapping(\"\/\")\r\n    public String home(){\r\n        return \"home\";\r\n    }\r\n}<\/pre>\n<p><strong>7.\u5728web\u7684jsp\u6587\u4ef6\u5939\u521b\u5efahome.jsp\u6587\u4ef6<\/strong><\/p>\n<p><strong>8.\u914d\u7f6eTomcat<\/strong><\/p>\n<p><strong>9.\u914d\u7f6ejdk\u63d2\u4ef6<\/strong><\/p>\n<p><strong>\u9ed8\u8ba4\u60c5\u51b5\u4e0b eclipse\u7684maven\u9879\u76ee\u4f7f\u7528jdk1.5\u7f16\u8bd1\uff0c\u9700\u8981\u6dfb\u52a0maven\u7684jdk\u7f16\u8bd1\u63d2\u4ef6<\/strong><\/p>\n<pre>&lt;properties&gt;\r\n  &lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;\r\n  &lt;maven.compiler.source&gt;1.8&lt;\/maven.compiler.source&gt;\r\n  &lt;maven.compiler.target&gt;1.8&lt;\/maven.compiler.target&gt;\r\n&lt;\/properties&gt;<\/pre>\n<pre>&lt;build&gt;\r\n  &lt;plugins&gt;\r\n    &lt;!-- java \u7f16\u8bd1\u63d2\u4ef6  --&gt;\r\n    &lt;plugin&gt;\r\n      &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n      &lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;\r\n      &lt;version&gt;3.8.0&lt;\/version&gt;\r\n      &lt;configuration&gt;\r\n        &lt;source&gt;1.8&lt;\/source&gt;\r\n        &lt;target&gt;1.8&lt;\/target&gt;\r\n        &lt;encoding&gt;${project.build.sourceEncoding}&lt;\/encoding&gt;\r\n      &lt;\/configuration&gt;\r\n    &lt;\/plugin&gt;\r\n  &lt;\/plugins&gt;\r\n&lt;\/build&gt;<\/pre>\n<p>maven\u9879\u76ee\u914d\u7f6etomcat<\/p>\n<pre>&lt;!--\u914d\u7f6e Tomcat \u63d2\u4ef6 --&gt;\r\n&lt;plugin&gt;\r\n  &lt;groupId&gt;org.apache.tomcat.maven&lt;\/groupId&gt;\r\n  &lt;artifactId&gt;tomcat7-maven-plugin&lt;\/artifactId&gt;\r\n  &lt;version&gt;2.2&lt;\/version&gt;\r\n  &lt;configuration&gt;\r\n    &lt;port&gt;8001&lt;\/port&gt;\r\n    &lt;path&gt;\/springmvc&lt;\/path&gt;\r\n  &lt;\/configuration&gt;\r\n&lt;\/plugin&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>2020java\u6846\u67b6\u6559\u7a0b\u4e4bspringMVC\u521b\u5efamaven\u9879\u76ee 1.\u521b\u5efaweb\u9879\u76ee 2.\u5bfc\u5165\u4f9d\u8d56 &lt;de [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2671","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2671"}],"version-history":[{"count":3,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2671\/revisions"}],"predecessor-version":[{"id":2684,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2671\/revisions\/2684"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}