{"id":63702,"date":"2026-01-22T08:48:36","date_gmt":"2026-01-22T00:48:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/63702.html"},"modified":"2026-01-22T08:48:36","modified_gmt":"2026-01-22T00:48:36","slug":"%e3%80%90day42%e3%80%91springmvc-%e5%85%a5%e9%97%a8%ef%bc%9adispatcherservlet-%e4%b8%8e%e8%af%b7%e6%b1%82%e6%98%a0%e5%b0%84","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/63702.html","title":{"rendered":"\u3010Day42\u3011SpringMVC \u5165\u95e8\uff1aDispatcherServlet \u4e0e\u8bf7\u6c42\u6620\u5c04"},"content":{"rendered":"<p>\u672c\u6587\u6536\u5f55\u4e8e\u300cJava \u5b66\u4e60\u65e5\u8bb0\u300d\u4e13\u680f&#xff0c;\u805a\u7126 SpringMVC \u7684\u6838\u5fc3\u9aa8\u67b6 \u2014\u2014DispatcherServlet \u524d\u7aef\u63a7\u5236\u5668\u4e0e\u8bf7\u6c42\u6620\u5c04\u673a\u5236&#xff0c;\u4ece\u5e95\u5c42\u6d41\u7a0b\u62c6\u89e3\u5230\u6ce8\u89e3\u5f0f\u5b9e\u6218&#xff0c;\u5e2e\u4f60\u6253\u901a SpringMVC \u5165\u95e8\u7684\u5173\u952e\u4e00\u6b65&#xff5e;<\/p>\n<h3>\u4e00\u3001\u4e3a\u4ec0\u4e48\u8981\u5b66 SpringMVC&#xff1f;<\/h3>\n<p>\u5728\u524d\u5e8f\u7684 Spring \u6838\u5fc3\u5b66\u4e60\u4e2d&#xff0c;\u6211\u4eec\u638c\u63e1\u4e86 IOC\/DI\u3001AOP \u7b49\u57fa\u7840&#xff0c;\u4f46\u5728 Web \u5f00\u53d1\u573a\u666f\u4e0b&#xff0c;\u8fd8\u9762\u4e34\u8fd9\u4e9b\u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\u624b\u52a8\u7f16\u5199 Servlet \u9700\u8981\u5904\u7406\u8bf7\u6c42\u5206\u53d1\u3001\u53c2\u6570\u89e3\u6790\u3001\u89c6\u56fe\u8df3\u8f6c\u7b49\u91cd\u590d\u903b\u8f91&#xff0c;\u5f00\u53d1\u6548\u7387\u4f4e&#xff1b;<\/li>\n<li>\u4f20\u7edf MVC \u624b\u52a8\u5b9e\u73b0\u7684\u6846\u67b6\u529f\u80fd\u7b80\u964b&#xff0c;\u65e0\u6cd5\u9002\u914d\u590d\u6742\u7684 Web \u573a\u666f&#xff08;\u5982 RESTful \u63a5\u53e3\u3001\u6587\u4ef6\u4e0a\u4f20&#xff09;&#xff1b;<\/li>\n<li>\u65e0\u6cd5\u4e0e Spring \u6838\u5fc3\u5bb9\u5668\u65e0\u7f1d\u6574\u5408&#xff0c;\u4f9d\u8d56\u6ce8\u5165\u3001AOP \u7b49\u7279\u6027\u65e0\u6cd5\u5728 Web \u5c42\u590d\u7528\u3002<\/li>\n<\/ul>\n<p>\u800cSpringMVC\u4f5c\u4e3a Spring \u6846\u67b6\u7684 Web \u6a21\u5757&#xff0c;\u5b8c\u7f8e\u89e3\u51b3\u4e86\u8fd9\u4e9b\u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\u57fa\u4e8e MVC \u8bbe\u8ba1\u6a21\u5f0f&#xff0c;\u5c01\u88c5\u4e86 Servlet \u5e95\u5c42\u7ec6\u8282&#xff0c;\u63d0\u4f9b\u7b80\u6d01\u7684\u6ce8\u89e3\u5f0f\u5f00\u53d1&#xff1b;<\/li>\n<li>\u6838\u5fc3\u7ec4\u4ef6 DispatcherServlet \u7edf\u4e00\u5904\u7406\u6240\u6709\u8bf7\u6c42&#xff0c;\u5b9e\u73b0\u8bf7\u6c42\u5206\u53d1\u3001\u53c2\u6570\u7ed1\u5b9a\u3001\u89c6\u56fe\u89e3\u6790\u7b49\u81ea\u52a8\u5316&#xff1b;<\/li>\n<li>\u4e0e Spring \u6838\u5fc3\u5bb9\u5668\u65e0\u7f1d\u6574\u5408&#xff0c;\u53ef\u76f4\u63a5\u590d\u7528 IOC\/DI\u3001AOP \u7b49\u7279\u6027&#xff1b;<\/li>\n<li>\u652f\u6301 RESTful API\u3001\u6587\u4ef6\u4e0a\u4f20\u3001\u62e6\u622a\u5668\u3001\u5f02\u5e38\u5904\u7406\u7b49\u4f01\u4e1a\u7ea7\u7279\u6027&#xff0c;\u662f Java Web \u5f00\u53d1\u7684\u4e3b\u6d41\u6846\u67b6\u3002<\/li>\n<\/ul>\n<p>\u4eca\u5929\u8fd9\u7bc7\u65e5\u8bb0&#xff0c;\u6211\u4eec\u4ece SpringMVC \u6838\u5fc3\u6d41\u7a0b\u5165\u624b&#xff0c;\u805a\u7126 DispatcherServlet \u548c\u8bf7\u6c42\u6620\u5c04\u4e24\u5927\u6838\u5fc3&#xff0c;\u901a\u8fc7\u5b9e\u6218\u638c\u63e1 SpringMVC \u7684\u5165\u95e8\u7528\u6cd5\u3002<\/p>\n<h3>\u4e8c\u3001SpringMVC \u6838\u5fc3\u67b6\u6784\u4e0e\u5de5\u4f5c\u6d41\u7a0b<\/h3>\n<h4>1. SpringMVC \u6838\u5fc3\u7ec4\u4ef6<\/h4>\n<p>SpringMVC \u7684\u6838\u5fc3\u662f \u201c\u524d\u7aef\u63a7\u5236\u5668 &#043; \u7ec4\u4ef6\u5316\u5904\u7406\u201d&#xff0c;\u6838\u5fc3\u7ec4\u4ef6\u5206\u5de5\u5982\u4e0b&#xff1a;<\/p>\n<table>\n<tr>\u7ec4\u4ef6\u4e2d\u6587\u540d\u79f0\u6838\u5fc3\u804c\u8d23<\/tr>\n<tbody>\n<tr>\n<td>DispatcherServlet<\/td>\n<td>\u524d\u7aef\u63a7\u5236\u5668<\/td>\n<td>\u63a5\u6536\u6240\u6709\u8bf7\u6c42&#xff0c;\u5206\u53d1\u5230\u5176\u4ed6\u7ec4\u4ef6&#xff0c;\u6838\u5fc3\u8c03\u5ea6\u8005<\/td>\n<\/tr>\n<tr>\n<td>HandlerMapping<\/td>\n<td>\u5904\u7406\u5668\u6620\u5c04\u5668<\/td>\n<td>\u6839\u636e\u8bf7\u6c42\u8def\u5f84\u5339\u914d\u5bf9\u5e94\u7684 Controller \u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>HandlerAdapter<\/td>\n<td>\u5904\u7406\u5668\u9002\u914d\u5668<\/td>\n<td>\u8c03\u7528 Controller \u65b9\u6cd5&#xff0c;\u5904\u7406\u53c2\u6570\u7ed1\u5b9a\u3001\u8fd4\u56de\u503c\u89e3\u6790<\/td>\n<\/tr>\n<tr>\n<td>Controller\/Handler<\/td>\n<td>\u5904\u7406\u5668&#xff08;\u63a7\u5236\u5668&#xff09;<\/td>\n<td>\u5904\u7406\u8bf7\u6c42\u903b\u8f91&#xff0c;\u8fd4\u56de\u89c6\u56fe\u540d \/ \u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>ViewResolver<\/td>\n<td>\u89c6\u56fe\u89e3\u6790\u5668<\/td>\n<td>\u5c06\u89c6\u56fe\u540d\u89e3\u6790\u4e3a\u5177\u4f53\u7684\u89c6\u56fe\u5bf9\u8c61&#xff08;\u5982 JSP\/HTML&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>View<\/td>\n<td>\u89c6\u56fe<\/td>\n<td>\u6e32\u67d3\u9875\u9762&#xff0c;\u8fd4\u56de\u54cd\u5e94\u7ed9\u5ba2\u6237\u7aef<\/td>\n<\/tr>\n<tr>\n<td>HandlerInterceptor<\/td>\n<td>\u62e6\u622a\u5668<\/td>\n<td>\u5bf9\u8bf7\u6c42\u8fdb\u884c\u524d\u7f6e \/ \u540e\u7f6e\u5904\u7406&#xff08;\u5982\u767b\u5f55\u6821\u9a8c&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2. SpringMVC \u5b8c\u6574\u5de5\u4f5c\u6d41\u7a0b&#xff08;\u6838\u5fc3&#xff09;<\/h4>\n<p>\u7528\u6d41\u7a0b\u56fe\u76f4\u89c2\u5c55\u793a\u8bf7\u6c42\u4ece\u5ba2\u6237\u7aef\u5230\u670d\u52a1\u7aef\u7684\u5168\u6d41\u7a0b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"2196\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260122004834-697173e2e3c01.png\" width=\"712\" \/><\/p>\n<h4>3. \u6838\u5fc3\u6d41\u7a0b\u62c6\u89e3&#xff08;\u901a\u4fd7\u7248&#xff09;<\/h4>\n<li>\u8bf7\u6c42\u8fdb\u95e8&#xff1a;\u6240\u6709\u8bf7\u6c42\u90fd\u5148\u5230 DispatcherServlet&#xff08;\u76f8\u5f53\u4e8e\u516c\u53f8\u524d\u53f0&#xff09;&#xff1b;<\/li>\n<li>\u627e\u5bf9\u5e94\u5458\u5de5&#xff1a;HandlerMapping \u6839\u636e\u8bf7\u6c42 URL \u627e\u5230\u5bf9\u5e94\u7684 Controller \u65b9\u6cd5&#xff08;\u524d\u53f0\u6839\u636e\u9700\u6c42\u627e\u5bf9\u5e94\u4e1a\u52a1\u5458\u5de5&#xff09;&#xff1b;<\/li>\n<li>\u9002\u914d\u8c03\u7528&#xff1a;HandlerAdapter \u8d1f\u8d23\u8c03\u7528 Controller \u65b9\u6cd5&#xff0c;\u5904\u7406\u53c2\u6570\u3001\u8fd4\u56de\u503c\u7b49\u7ec6\u8282&#xff08;\u884c\u653f\u5e2e\u5458\u5de5\u51c6\u5907\u597d\u5de5\u4f5c\u6761\u4ef6&#xff09;&#xff1b;<\/li>\n<li>\u5904\u7406\u4e1a\u52a1&#xff1a;Controller \u5904\u7406\u5177\u4f53\u4e1a\u52a1\u903b\u8f91&#xff0c;\u8fd4\u56de\u89c6\u56fe\u540d&#xff08;\u5458\u5de5\u5904\u7406\u5177\u4f53\u5de5\u4f5c&#xff0c;\u544a\u8bc9\u524d\u53f0\u7ed3\u679c&#xff09;&#xff1b;<\/li>\n<li>\u627e\u89c6\u56fe\u9875\u9762&#xff1a;ViewResolver \u6839\u636e\u89c6\u56fe\u540d\u627e\u5230\u5177\u4f53\u7684\u9875\u9762&#xff08;\u524d\u53f0\u6839\u636e\u7ed3\u679c\u627e\u5bf9\u5e94\u7684\u8f93\u51fa\u6a21\u677f&#xff09;&#xff1b;<\/li>\n<li>\u8fd4\u56de\u54cd\u5e94&#xff1a;View \u6e32\u67d3\u9875\u9762\u5e76\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef&#xff08;\u8f93\u51fa\u6700\u7ec8\u7ed3\u679c&#xff09;\u3002<\/li>\n<h3>\u4e09\u3001SpringMVC \u5165\u95e8\u5b9e\u6218&#xff1a;\u73af\u5883\u642d\u5efa\u4e0e\u6838\u5fc3\u914d\u7f6e<\/h3>\n<h4>1. \u5f00\u53d1\u73af\u5883\u51c6\u5907<\/h4>\n<ul>\n<li>JDK&#xff1a;8 \u53ca\u4ee5\u4e0a&#xff1b;<\/li>\n<li>\u6784\u5efa\u5de5\u5177&#xff1a;Maven&#xff1b;<\/li>\n<li>Web \u5bb9\u5668&#xff1a;Tomcat 8.5&#043;&#xff1b;<\/li>\n<li>SpringMVC \u7248\u672c&#xff1a;5.3.x&#xff08;\u4e0e Spring \u6838\u5fc3\u7248\u672c\u4e00\u81f4&#xff09;\u3002<\/li>\n<\/ul>\n<h4>2. Maven \u4f9d\u8d56\u914d\u7f6e&#xff08;\u6838\u5fc3&#xff09;<\/h4>\n<p>xml<\/p>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;project xmlns&#061;&#034;http:\/\/maven.apache.org\/POM\/4.0.0&#034;<br \/>\n         xmlns:xsi&#061;&#034;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#034;<br \/>\n         xsi:schemaLocation&#061;&#034;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd&#034;&gt;<br \/>\n    &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;<\/p>\n<p>    &lt;groupId&gt;com.example&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;springmvc-demo&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;<br \/>\n    &lt;packaging&gt;war&lt;\/packaging&gt;<\/p>\n<p>    &lt;properties&gt;<br \/>\n        &lt;spring.version&gt;5.3.29&lt;\/spring.version&gt;<br \/>\n        &lt;maven.compiler.source&gt;8&lt;\/maven.compiler.source&gt;<br \/>\n        &lt;maven.compiler.target&gt;8&lt;\/maven.compiler.target&gt;<br \/>\n    &lt;\/properties&gt;<\/p>\n<p>    &lt;dependencies&gt;<br \/>\n        &lt;!&#8211; SpringMVC\u6838\u5fc3\u4f9d\u8d56 &#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;spring-webmvc&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;${spring.version}&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;!&#8211; Servlet API&#xff08;Tomcat\u5df2\u63d0\u4f9b&#xff0c;\u7f16\u8bd1\u65f6\u4f9d\u8d56&#xff09; &#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;javax.servlet&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;javax.servlet-api&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;4.0.1&lt;\/version&gt;<br \/>\n            &lt;scope&gt;provided&lt;\/scope&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;!&#8211; JSP API&#xff08;Tomcat\u5df2\u63d0\u4f9b&#xff09; &#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;javax.servlet.jsp&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;jsp-api&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;2.2&lt;\/version&gt;<br \/>\n            &lt;scope&gt;provided&lt;\/scope&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;!&#8211; JSTL&#xff08;JSP\u6807\u7b7e\u5e93&#xff09; &#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;jstl&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;jstl&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;1.2&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n    &lt;\/dependencies&gt;<\/p>\n<p>    &lt;!&#8211; \u6784\u5efa\u914d\u7f6e&#xff1a;\u6307\u5b9awar\u5305\u540d\u79f0\u3001\u7f16\u8bd1\u63d2\u4ef6 &#8211;&gt;<br \/>\n    &lt;build&gt;<br \/>\n        &lt;finalName&gt;springmvc-demo&lt;\/finalName&gt;<br \/>\n        &lt;plugins&gt;<br \/>\n            &lt;plugin&gt;<br \/>\n                &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;<br \/>\n                &lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;<br \/>\n                &lt;version&gt;3.8.1&lt;\/version&gt;<br \/>\n                &lt;configuration&gt;<br \/>\n                    &lt;source&gt;8&lt;\/source&gt;<br \/>\n                    &lt;target&gt;8&lt;\/target&gt;<br \/>\n                &lt;\/configuration&gt;<br \/>\n            &lt;\/plugin&gt;<br \/>\n            &lt;!&#8211; Tomcat\u63d2\u4ef6&#xff08;\u65b9\u4fbf\u8fd0\u884c&#xff09; &#8211;&gt;<br \/>\n            &lt;plugin&gt;<br \/>\n                &lt;groupId&gt;org.apache.tomcat.maven&lt;\/groupId&gt;<br \/>\n                &lt;artifactId&gt;tomcat7-maven-plugin&lt;\/artifactId&gt;<br \/>\n                &lt;version&gt;2.2&lt;\/version&gt;<br \/>\n                &lt;configuration&gt;<br \/>\n                    &lt;port&gt;8080&lt;\/port&gt;<br \/>\n                    &lt;path&gt;\/&lt;\/path&gt;<br \/>\n                &lt;\/configuration&gt;<br \/>\n            &lt;\/plugin&gt;<br \/>\n        &lt;\/plugins&gt;<br \/>\n    &lt;\/build&gt;<br \/>\n&lt;\/project&gt;<\/p>\n<h4>3. \u914d\u7f6e DispatcherServlet&#xff08;web.xml&#xff09;<\/h4>\n<p>DispatcherServlet \u662f SpringMVC \u7684\u6838\u5fc3&#xff0c;\u9700\u8981\u5728web.xml\u4e2d\u914d\u7f6e&#xff08;\u76f8\u5f53\u4e8e\u6ce8\u518c \u201c\u524d\u53f0\u201d&#xff09;&#xff1a;<\/p>\n<p>xml<\/p>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;web-app xmlns&#061;&#034;http:\/\/xmlns.jcp.org\/xml\/ns\/javaee&#034;<br \/>\n         xmlns:xsi&#061;&#034;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#034;<br \/>\n         xsi:schemaLocation&#061;&#034;http:\/\/xmlns.jcp.org\/xml\/ns\/javaee http:\/\/xmlns.jcp.org\/xml\/ns\/javaee\/web-app_4_0.xsd&#034;<br \/>\n         version&#061;&#034;4.0&#034;&gt;<\/p>\n<p>    &lt;!&#8211; \u914d\u7f6eSpringMVC\u524d\u7aef\u63a7\u5236\u5668DispatcherServlet &#8211;&gt;<br \/>\n    &lt;servlet&gt;<br \/>\n        &lt;servlet-name&gt;springmvc&lt;\/servlet-name&gt;<br \/>\n        &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;\/servlet-class&gt;<br \/>\n        &lt;!&#8211; \u6307\u5b9aSpringMVC\u914d\u7f6e\u6587\u4ef6\u8def\u5f84&#xff08;\u9ed8\u8ba4\/WEB-INF\/[servlet-name]-servlet.xml&#xff09; &#8211;&gt;<br \/>\n        &lt;init-param&gt;<br \/>\n            &lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;<br \/>\n            &lt;param-value&gt;classpath:springmvc-config.xml&lt;\/param-value&gt;<br \/>\n        &lt;\/init-param&gt;<br \/>\n        &lt;!&#8211; \u542f\u52a8\u65f6\u52a0\u8f7d&#xff08;\u4f18\u5148\u7ea71&#xff09;&#xff0c;Tomcat\u542f\u52a8\u65f6\u5c31\u521d\u59cb\u5316DispatcherServlet &#8211;&gt;<br \/>\n        &lt;load-on-startup&gt;1&lt;\/load-on-startup&gt;<br \/>\n    &lt;\/servlet&gt;<\/p>\n<p>    &lt;!&#8211; \u6620\u5c04\u6240\u6709\u8bf7\u6c42\u5230DispatcherServlet &#8211;&gt;<br \/>\n    &lt;servlet-mapping&gt;<br \/>\n        &lt;servlet-name&gt;springmvc&lt;\/servlet-name&gt;<br \/>\n        &lt;!&#8211; \/&#xff1a;\u5339\u914d\u6240\u6709\u8bf7\u6c42&#xff08;\u9664\u4e86JSP&#xff09;&#xff0c;\/*&#xff1a;\u5339\u914d\u6240\u6709\u8bf7\u6c42&#xff08;\u5305\u62ecJSP&#xff0c;\u4e0d\u63a8\u8350&#xff09; &#8211;&gt;<br \/>\n        &lt;url-pattern&gt;\/&lt;\/url-pattern&gt;<br \/>\n    &lt;\/servlet-mapping&gt;<\/p>\n<p>    &lt;!&#8211; \u5b57\u7b26\u7f16\u7801\u8fc7\u6ee4\u5668&#xff08;\u89e3\u51b3POST\u8bf7\u6c42\u4e2d\u6587\u4e71\u7801&#xff09; &#8211;&gt;<br \/>\n    &lt;filter&gt;<br \/>\n        &lt;filter-name&gt;characterEncodingFilter&lt;\/filter-name&gt;<br \/>\n        &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;\/filter-class&gt;<br \/>\n        &lt;init-param&gt;<br \/>\n            &lt;param-name&gt;encoding&lt;\/param-name&gt;<br \/>\n            &lt;param-value&gt;UTF-8&lt;\/param-value&gt;<br \/>\n        &lt;\/init-param&gt;<br \/>\n        &lt;init-param&gt;<br \/>\n            &lt;param-name&gt;forceEncoding&lt;\/param-name&gt;<br \/>\n            &lt;param-value&gt;true&lt;\/param-value&gt;<br \/>\n        &lt;\/init-param&gt;<br \/>\n    &lt;\/filter&gt;<br \/>\n    &lt;filter-mapping&gt;<br \/>\n        &lt;filter-name&gt;characterEncodingFilter&lt;\/filter-name&gt;<br \/>\n        &lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;<br \/>\n    &lt;\/filter-mapping&gt;<br \/>\n&lt;\/web-app&gt;<\/p>\n<h4>4. SpringMVC \u6838\u5fc3\u914d\u7f6e\u6587\u4ef6&#xff08;springmvc-config.xml&#xff09;<\/h4>\n<p>xml<\/p>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;beans xmlns&#061;&#034;http:\/\/www.springframework.org\/schema\/beans&#034;<br \/>\n       xmlns:xsi&#061;&#034;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#034;<br \/>\n       xmlns:context&#061;&#034;http:\/\/www.springframework.org\/schema\/context&#034;<br \/>\n       xmlns:mvc&#061;&#034;http:\/\/www.springframework.org\/schema\/mvc&#034;<br \/>\n       xsi:schemaLocation&#061;&#034;http:\/\/www.springframework.org\/schema\/beans<br \/>\n       http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd<br \/>\n       http:\/\/www.springframework.org\/schema\/context<br \/>\n       http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd<br \/>\n       http:\/\/www.springframework.org\/schema\/mvc<br \/>\n       http:\/\/www.springframework.org\/schema\/mvc\/spring-mvc.xsd&#034;&gt;<\/p>\n<p>    &lt;!&#8211; 1. \u626b\u63cfController\u5305\u4e0b\u7684\u6ce8\u89e3&#xff08;&#064;Controller\/&#064;RequestMapping\u7b49&#xff09; &#8211;&gt;<br \/>\n    &lt;context:component-scan base-package&#061;&#034;com.example.controller&#034;\/&gt;<\/p>\n<p>    &lt;!&#8211; 2. \u5f00\u542fSpringMVC\u6ce8\u89e3\u9a71\u52a8&#xff08;\u652f\u6301&#064;RequestMapping\u3001\u53c2\u6570\u7ed1\u5b9a\u7b49&#xff09; &#8211;&gt;<br \/>\n    &lt;mvc:annotation-driven\/&gt;<\/p>\n<p>    &lt;!&#8211; 3. \u914d\u7f6e\u89c6\u56fe\u89e3\u6790\u5668&#xff08;\u5c06\u89c6\u56fe\u540d\u89e3\u6790\u4e3aJSP\u8def\u5f84&#xff09; &#8211;&gt;<br \/>\n    &lt;bean class&#061;&#034;org.springframework.web.servlet.view.InternalResourceViewResolver&#034;&gt;<br \/>\n        &lt;!&#8211; \u524d\u7f00&#xff1a;JSP\u6587\u4ef6\u6240\u5728\u76ee\u5f55 &#8211;&gt;<br \/>\n        &lt;property name&#061;&#034;prefix&#034; value&#061;&#034;\/WEB-INF\/views\/&#034;\/&gt;<br \/>\n        &lt;!&#8211; \u540e\u7f00&#xff1a;JSP\u6587\u4ef6\u540e\u7f00 &#8211;&gt;<br \/>\n        &lt;property name&#061;&#034;suffix&#034; value&#061;&#034;.jsp&#034;\/&gt;<br \/>\n    &lt;\/bean&gt;<\/p>\n<p>    &lt;!&#8211; 4. \u9759\u6001\u8d44\u6e90\u653e\u884c&#xff08;\u5982CSS\/JS\/\u56fe\u7247&#xff0c;\u5426\u5219DispatcherServlet\u4f1a\u62e6\u622a&#xff09; &#8211;&gt;<br \/>\n    &lt;mvc:default-servlet-handler\/&gt;<br \/>\n&lt;\/beans&gt;<\/p>\n<h3>\u56db\u3001\u8bf7\u6c42\u6620\u5c04\u5b9e\u6218&#xff1a;&#064;RequestMapping \u6ce8\u89e3<\/h3>\n<h4>1. \u6838\u5fc3\u6ce8\u89e3\u8bf4\u660e<\/h4>\n<p>&#064;RequestMapping\u662f SpringMVC \u4e2d\u6700\u6838\u5fc3\u7684\u8bf7\u6c42\u6620\u5c04\u6ce8\u89e3&#xff0c;\u7528\u4e8e\u5c06\u8bf7\u6c42 URL \u7ed1\u5b9a\u5230 Controller \u65b9\u6cd5&#xff0c;\u652f\u6301\u7c7b\u7ea7\u548c\u65b9\u6cd5\u7ea7\u6ce8\u89e3&#xff1a;<\/p>\n<table>\n<tr>\u6ce8\u89e3\u5c5e\u6027\u4f5c\u7528\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>value\/path<\/td>\n<td>\u6307\u5b9a\u8bf7\u6c42 URL \u8def\u5f84<\/td>\n<td>&#064;RequestMapping(&#034;\/user\/query&#034;)<\/td>\n<\/tr>\n<tr>\n<td>method<\/td>\n<td>\u6307\u5b9a\u8bf7\u6c42\u65b9\u5f0f&#xff08;GET\/POST\/PUT\/DELETE&#xff09;<\/td>\n<td>method &#061; RequestMethod.GET<\/td>\n<\/tr>\n<tr>\n<td>params<\/td>\n<td>\u6307\u5b9a\u8bf7\u6c42\u5fc5\u987b\u5305\u542b\u7684\u53c2\u6570<\/td>\n<td>params &#061; &#034;id&#034;&#xff08;\u5fc5\u987b\u6709 id \u53c2\u6570&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>headers<\/td>\n<td>\u6307\u5b9a\u8bf7\u6c42\u5fc5\u987b\u5305\u542b\u7684\u8bf7\u6c42\u5934<\/td>\n<td>headers &#061; &#034;Content-Type&#061;application\/json&#034;<\/td>\n<\/tr>\n<tr>\n<td>produces<\/td>\n<td>\u6307\u5b9a\u54cd\u5e94\u5185\u5bb9\u7c7b\u578b<\/td>\n<td>produces &#061; &#034;application\/json&#034;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2. \u7f16\u5199 Controller&#xff08;\u6838\u5fc3&#xff09;<\/h4>\n<p>java<\/p>\n<p>\u8fd0\u884c<\/p>\n<p>package com.example.controller;<\/p>\n<p>import org.springframework.stereotype.Controller;<br \/>\nimport org.springframework.ui.Model;<br \/>\nimport org.springframework.web.bind.annotation.*;<\/p>\n<p>import javax.servlet.http.HttpServletRequest;<\/p>\n<p>\/\/ \u6807\u8bb0\u4e3aSpringMVC\u63a7\u5236\u5668&#xff08;\u7531SpringMVC\u5bb9\u5668\u7ba1\u7406&#xff09;<br \/>\n&#064;Controller<br \/>\n\/\/ \u7c7b\u7ea7\u8bf7\u6c42\u6620\u5c04&#xff1a;\u6240\u6709\u65b9\u6cd5\u7684URL\u524d\u7f00\u4e3a\/user<br \/>\n&#064;RequestMapping(&#034;\/user&#034;)<br \/>\npublic class UserController {<\/p>\n<p>    \/\/ 1. \u57fa\u7840\u6620\u5c04&#xff1a;GET\u8bf7\u6c42 \/user\/query \u2192 \u5339\u914d\u8be5\u65b9\u6cd5<br \/>\n    &#064;RequestMapping(value &#061; &#034;\/query&#034;, method &#061; RequestMethod.GET)<br \/>\n    public String queryUser(HttpServletRequest request, Model model) {<br \/>\n        \/\/ 1. \u83b7\u53d6\u8bf7\u6c42\u53c2\u6570&#xff08;\u539f\u751fServlet\u65b9\u5f0f&#xff09;<br \/>\n        String userId &#061; request.getParameter(&#034;id&#034;);<br \/>\n        \/\/ 2. \u5c01\u88c5\u6570\u636e\u5230Model&#xff08;\u4f20\u9012\u5230\u89c6\u56fe&#xff09;<br \/>\n        model.addAttribute(&#034;userId&#034;, userId);<br \/>\n        model.addAttribute(&#034;username&#034;, &#034;Java\u65e5\u8bb0&#034;);<br \/>\n        \/\/ 3. \u8fd4\u56de\u89c6\u56fe\u540d&#xff08;\u89c6\u56fe\u89e3\u6790\u5668\u4f1a\u89e3\u6790\u4e3a\/WEB-INF\/views\/userInfo.jsp&#xff09;<br \/>\n        return &#034;userInfo&#034;;<br \/>\n    }<\/p>\n<p>    \/\/ 2. \u7b80\u5316\u53c2\u6570\u7ed1\u5b9a&#xff1a;\u76f4\u63a5\u5c06\u53c2\u6570\u7ed1\u5b9a\u5230\u65b9\u6cd5\u53c2\u6570<br \/>\n    &#064;GetMapping(&#034;\/detail&#034;) \/\/ &#064;GetMapping &#061; &#064;RequestMapping(method&#061;GET)<br \/>\n    public String userDetail(&#064;RequestParam(&#034;id&#034;) String userId,<br \/>\n                             &#064;RequestParam(defaultValue &#061; &#034;18&#034;) Integer age,<br \/>\n                             Model model) {<br \/>\n        model.addAttribute(&#034;msg&#034;, &#034;\u7528\u6237ID&#xff1a;&#034; &#043; userId &#043; &#034;&#xff0c;\u5e74\u9f84&#xff1a;&#034; &#043; age);<br \/>\n        return &#034;detail&#034;;<br \/>\n    }<\/p>\n<p>    \/\/ 3. \u8def\u5f84\u53d8\u91cf&#xff1a;RESTful\u98ce\u683c&#xff08;URL\u4e2d\u5d4c\u5165\u53c2\u6570&#xff09;<br \/>\n    &#064;GetMapping(&#034;\/{id}\/info&#034;)<br \/>\n    public String restfulDemo(&#064;PathVariable(&#034;id&#034;) String userId, Model model) {<br \/>\n        model.addAttribute(&#034;restMsg&#034;, &#034;RESTful\u98ce\u683c&#xff1a;\u7528\u6237ID&#061;&#034; &#043; userId);<br \/>\n        return &#034;restful&#034;;<br \/>\n    }<\/p>\n<p>    \/\/ 4. POST\u8bf7\u6c42\u6620\u5c04&#xff08;\u914d\u5408\u8868\u5355\u63d0\u4ea4&#xff09;<br \/>\n    &#064;PostMapping(&#034;\/save&#034;) \/\/ &#064;PostMapping &#061; &#064;RequestMapping(method&#061;POST)<br \/>\n    public String saveUser(&#064;RequestParam(&#034;username&#034;) String username,<br \/>\n                           &#064;RequestParam(&#034;password&#034;) String password,<br \/>\n                           Model model) {<br \/>\n        model.addAttribute(&#034;saveMsg&#034;, &#034;\u4fdd\u5b58\u7528\u6237&#xff1a;&#034; &#043; username &#043; &#034; \u6210\u529f&#034;);<br \/>\n        \/\/ \u91cd\u5b9a\u5411&#xff08;\u4e0d\u4f1a\u7ecf\u8fc7\u89c6\u56fe\u89e3\u6790\u5668&#xff0c;\u9700\u52a0redirect:\u524d\u7f00&#xff09;<br \/>\n        return &#034;redirect:\/user\/success&#034;;<br \/>\n    }<\/p>\n<p>    \/\/ 5. \u8df3\u8f6c\u6210\u529f\u9875<br \/>\n    &#064;GetMapping(&#034;\/success&#034;)<br \/>\n    public String success() {<br \/>\n        return &#034;success&#034;;<br \/>\n    }<\/p>\n<p>    \/\/ 6. \u54cd\u5e94JSON\u6570\u636e&#xff08;&#064;ResponseBody&#xff1a;\u8fd4\u56de\u503c\u76f4\u63a5\u4f5c\u4e3a\u54cd\u5e94\u4f53&#xff0c;\u4e0d\u89e3\u6790\u4e3a\u89c6\u56fe&#xff09;<br \/>\n    &#064;GetMapping(&#034;\/json&#034;)<br \/>\n    &#064;ResponseBody<br \/>\n    public String getJson() {<br \/>\n        return &#034;{\\\\&#034;code\\\\&#034;:200,\\\\&#034;msg\\\\&#034;:\\\\&#034;success\\\\&#034;}&#034;;<br \/>\n    }<br \/>\n}<\/p>\n<h4>3. \u7f16\u5199\u89c6\u56fe\u9875\u9762<\/h4>\n<h5>&#xff08;1&#xff09;\u7528\u6237\u4fe1\u606f\u9875&#xff1a;\/WEB-INF\/views\/userInfo.jsp<\/h5>\n<p>jsp<\/p>\n<p>&lt;%&#064; page contentType&#061;&#034;text\/html;charset&#061;UTF-8&#034; language&#061;&#034;java&#034; %&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n    &lt;title&gt;\u7528\u6237\u4fe1\u606f&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n    &lt;h1&gt;\u7528\u6237\u4fe1\u606f\u9875\u9762&lt;\/h1&gt;<br \/>\n    &lt;p&gt;\u7528\u6237ID&#xff1a;${userId}&lt;\/p&gt;<br \/>\n    &lt;p&gt;\u7528\u6237\u540d&#xff1a;${username}&lt;\/p&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h5>&#xff08;2&#xff09;\u8868\u5355\u9875&#xff1a;\/WEB-INF\/views\/form.jsp<\/h5>\n<p>jsp<\/p>\n<p>&lt;%&#064; page contentType&#061;&#034;text\/html;charset&#061;UTF-8&#034; language&#061;&#034;java&#034; %&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n    &lt;title&gt;\u7528\u6237\u8868\u5355&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n    &lt;h1&gt;\u7528\u6237\u6ce8\u518c&lt;\/h1&gt;<br \/>\n    &lt;form action&#061;&#034;${pageContext.request.contextPath}\/user\/save&#034; method&#061;&#034;post&#034;&gt;<br \/>\n        \u7528\u6237\u540d&#xff1a;&lt;input type&#061;&#034;text&#034; name&#061;&#034;username&#034;&gt;&lt;br&gt;<br \/>\n        \u5bc6\u7801&#xff1a;&lt;input type&#061;&#034;password&#034; name&#061;&#034;password&#034;&gt;&lt;br&gt;<br \/>\n        &lt;input type&#061;&#034;submit&#034; value&#061;&#034;\u63d0\u4ea4&#034;&gt;<br \/>\n    &lt;\/form&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h5>&#xff08;3&#xff09;\u6210\u529f\u9875&#xff1a;\/WEB-INF\/views\/success.jsp<\/h5>\n<p>jsp<\/p>\n<p>&lt;%&#064; page contentType&#061;&#034;text\/html;charset&#061;UTF-8&#034; language&#061;&#034;java&#034; %&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n    &lt;title&gt;\u6210\u529f\u9875&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n    &lt;h1&gt;\u64cd\u4f5c\u6210\u529f&lt;\/h1&gt;<br \/>\n    &lt;p&gt;${saveMsg}&lt;\/p&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h4>4. \u6d4b\u8bd5\u8bf7\u6c42\u6620\u5c04<\/h4>\n<h5>&#xff08;1&#xff09;\u6d4b\u8bd5 GET \u8bf7\u6c42<\/h5>\n<p>\u8bbf\u95ee&#xff1a;http:\/\/localhost:8080\/user\/query?id&#061;1001\u6548\u679c&#xff1a;\u8df3\u8f6c\u5230userInfo.jsp&#xff0c;\u5c55\u793a\u7528\u6237 ID \u548c\u7528\u6237\u540d\u3002<\/p>\n<h5>&#xff08;2&#xff09;\u6d4b\u8bd5 RESTful \u98ce\u683c<\/h5>\n<p>\u8bbf\u95ee&#xff1a;http:\/\/localhost:8080\/user\/1002\/info\u6548\u679c&#xff1a;\u8df3\u8f6c\u5230restful.jsp&#xff0c;\u5c55\u793a RESTful \u98ce\u683c\u7684\u7528\u6237 ID\u3002<\/p>\n<h5>&#xff08;3&#xff09;\u6d4b\u8bd5 POST \u8bf7\u6c42<\/h5>\n<li>\u8bbf\u95ee&#xff1a;http:\/\/localhost:8080\/user\/form&#xff08;\u9700\u65b0\u589e form \u65b9\u6cd5\u8fd4\u56de form \u89c6\u56fe&#xff09;&#xff1b;<\/li>\n<li>\u586b\u5199\u8868\u5355\u5e76\u63d0\u4ea4&#xff0c;\u4f1a\u8df3\u8f6c\u5230success.jsp&#xff0c;\u5c55\u793a\u4fdd\u5b58\u6210\u529f\u4fe1\u606f\u3002<\/li>\n<h5>&#xff08;4&#xff09;\u6d4b\u8bd5 JSON \u54cd\u5e94<\/h5>\n<p>\u8bbf\u95ee&#xff1a;http:\/\/localhost:8080\/user\/json\u6548\u679c&#xff1a;\u76f4\u63a5\u8fd4\u56de JSON \u5b57\u7b26\u4e32&#xff0c;\u800c\u975e\u8df3\u8f6c\u9875\u9762\u3002<\/p>\n<h4>5. \u7b80\u5316\u6ce8\u89e3&#xff08;Spring4.3&#043;&#xff09;<\/h4>\n<p>\u4e3a\u4e86\u7b80\u5316&#064;RequestMapping\u7684 method \u5c5e\u6027&#xff0c;Spring \u63d0\u4f9b\u4e86\u4e13\u7528\u6ce8\u89e3&#xff1a;<\/p>\n<table>\n<tr>\u7b80\u5316\u6ce8\u89e3\u7b49\u4ef7\u4e8e<\/tr>\n<tbody>\n<tr>\n<td>&#064;GetMapping<\/td>\n<td>&#064;RequestMapping(method&#061;RequestMethod.GET)<\/td>\n<\/tr>\n<tr>\n<td>&#064;PostMapping<\/td>\n<td>&#064;RequestMapping(method&#061;RequestMethod.POST)<\/td>\n<\/tr>\n<tr>\n<td>&#064;PutMapping<\/td>\n<td>&#064;RequestMapping(method&#061;RequestMethod.PUT)<\/td>\n<\/tr>\n<tr>\n<td>&#064;DeleteMapping<\/td>\n<td>&#064;RequestMapping(method&#061;RequestMethod.DELETE)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4e94\u3001\u6838\u5fc3\u907f\u5751\u6307\u5357<\/h3>\n<h4>1. \u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h4>\n<table>\n<tr>\u95ee\u9898\u73b0\u8c61\u6839\u56e0\u89e3\u51b3\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td>404 \u9519\u8bef&#xff08;\u9875\u9762\u627e\u4e0d\u5230&#xff09;<\/td>\n<td>1. \u89c6\u56fe\u89e3\u6790\u5668\u524d\u7f00 \/ \u540e\u7f00\u914d\u7f6e\u9519\u8bef&#xff1b;2. JSP \u6587\u4ef6\u8def\u5f84\u9519\u8bef&#xff1b;3. \u8fd4\u56de\u89c6\u56fe\u540d\u9519\u8bef<\/td>\n<td>1. \u6838\u5bf9 prefix\/suffix&#xff1b;2. \u68c0\u67e5 JSP \u662f\u5426\u5728 \/ WEB-INF\/views\/ \u4e0b&#xff1b;3. \u6838\u5bf9\u8fd4\u56de\u7684\u89c6\u56fe\u540d<\/td>\n<\/tr>\n<tr>\n<td>405 \u9519\u8bef&#xff08;\u8bf7\u6c42\u65b9\u6cd5\u4e0d\u5141\u8bb8&#xff09;<\/td>\n<td>&#064;RequestMapping \u7684 method \u4e0e\u5b9e\u9645\u8bf7\u6c42\u65b9\u5f0f\u4e0d\u5339\u914d<\/td>\n<td>1. \u68c0\u67e5 method \u5c5e\u6027&#xff1b;2. \u6539\u7528 &#064;GetMapping\/&#064;PostMapping<\/td>\n<\/tr>\n<tr>\n<td>\u9759\u6001\u8d44\u6e90&#xff08;CSS\/JS&#xff09;\u65e0\u6cd5\u8bbf\u95ee<\/td>\n<td>DispatcherServlet \u62e6\u622a\u4e86\u9759\u6001\u8d44\u6e90<\/td>\n<td>\u6dfb\u52a0&lt;mvc:default-servlet-handler\/&gt;\u653e\u884c\u9759\u6001\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>POST \u8bf7\u6c42\u4e2d\u6587\u4e71\u7801<\/td>\n<td>\u672a\u914d\u7f6e\u5b57\u7b26\u7f16\u7801\u8fc7\u6ee4\u5668<\/td>\n<td>\u5728 web.xml \u4e2d\u914d\u7f6e CharacterEncodingFilter<\/td>\n<\/tr>\n<tr>\n<td>&#064;ResponseBody \u8fd4\u56de\u4e2d\u6587\u4e71\u7801<\/td>\n<td>\u54cd\u5e94\u7f16\u7801\u672a\u8bbe\u7f6e<\/td>\n<td>\u5728&lt;mvc:annotation-driven\/&gt;\u4e2d\u914d\u7f6e\u6d88\u606f\u8f6c\u6362\u5668&#xff0c;\u8bbe\u7f6e UTF-8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2. \u6700\u4f73\u5b9e\u8df5<\/h4>\n<li>URL \u8bbe\u8ba1&#xff1a;\u9075\u5faa RESTful \u98ce\u683c&#xff0c;\u7528 URL \u8868\u793a\u8d44\u6e90&#xff0c;\u7528\u8bf7\u6c42\u65b9\u5f0f\u8868\u793a\u64cd\u4f5c&#xff08;GET \u67e5\u8be2\u3001POST \u65b0\u589e\u3001PUT \u4fee\u6539\u3001DELETE \u5220\u9664&#xff09;&#xff1b;<\/li>\n<li>\u53c2\u6570\u7ed1\u5b9a&#xff1a;\u4f18\u5148\u4f7f\u7528&#064;RequestParam\/&#064;PathVariable&#xff0c;\u800c\u975e\u539f\u751f HttpServletRequest&#xff0c;\u4ee3\u7801\u66f4\u7b80\u6d01&#xff1b;<\/li>\n<li>\u89c6\u56fe\u8df3\u8f6c&#xff1a;\n<ul>\n<li>\u670d\u52a1\u5668\u5185\u90e8\u8df3\u8f6c&#xff1a;\u8fd4\u56de\u89c6\u56fe\u540d&#xff08;\u5982return &#034;userInfo&#034;&#xff09;&#xff1b;<\/li>\n<li>\u91cd\u5b9a\u5411&#xff1a;\u52a0redirect:\u524d\u7f00&#xff08;\u5982return &#034;redirect:\/user\/success&#034;&#xff09;&#xff1b;<\/li>\n<li>\u54cd\u5e94 JSON&#xff1a;\u52a0&#064;ResponseBody\u6ce8\u89e3&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>\u5305\u626b\u63cf&#xff1a;context:component-scan\u4ec5\u626b\u63cf Controller \u5305&#xff08;com.example.controller&#xff09;&#xff0c;\u907f\u514d\u626b\u63cf Service\/DAO&#xff0c;\u63d0\u5347\u6027\u80fd&#xff1b;<\/li>\n<li>\u9759\u6001\u8d44\u6e90&#xff1a;\u5c06 CSS\/JS\/ \u56fe\u7247\u653e\u5728webapp\/static\u76ee\u5f55\u4e0b&#xff0c;\u901a\u8fc7&lt;mvc:default-servlet-handler\/&gt;\u653e\u884c\u3002<\/li>\n<h3>\u516d\u3001\u4eca\u65e5\u5b9e\u6218\u5c0f\u4efb\u52a1<\/h3>\n<li>\u57fa\u4e8e\u5b9e\u6218\u6848\u4f8b&#xff0c;\u65b0\u589e&#064;PutMapping(&#034;\/{id}\/update&#034;)\u548c&#064;DeleteMapping(&#034;\/{id}\/delete&#034;)\u65b9\u6cd5&#xff0c;\u5b9e\u73b0 RESTful \u98ce\u683c\u7684\u4fee\u6539\u548c\u5220\u9664&#xff1b;<\/li>\n<li>\u65b0\u589e\u4e00\u4e2a\u767b\u5f55\u9875\u9762&#xff08;login.jsp&#xff09;&#xff0c;\u901a\u8fc7&#064;PostMapping(&#034;\/login&#034;)\u5904\u7406\u767b\u5f55\u8bf7\u6c42&#xff0c;\u6821\u9a8c\u7528\u6237\u540d\u5bc6\u7801&#xff08;admin\/123456&#xff09;&#xff0c;\u6210\u529f\u5219\u91cd\u5b9a\u5411\u5230\u9996\u9875&#xff0c;\u5931\u8d25\u5219\u8fd4\u56de\u767b\u5f55\u9875\u5e76\u63d0\u793a\u9519\u8bef\u4fe1\u606f&#xff1b;<\/li>\n<li>\u914d\u7f6e&#064;ResponseBody\u8fd4\u56de JSON \u65f6\u7684\u4e2d\u6587\u4e71\u7801\u95ee\u9898&#xff0c;\u901a\u8fc7&lt;mvc:annotation-driven\/&gt;\u914d\u7f6e StringHttpMessageConverter \u7684\u7f16\u7801\u4e3a UTF-8\u3002<\/li>\n<hr \/>\n<h4>\u603b\u7ed3<\/h4>\n<li>SpringMVC \u7684\u6838\u5fc3\u662f DispatcherServlet \u524d\u7aef\u63a7\u5236\u5668&#xff0c;\u7edf\u4e00\u63a5\u6536\u5e76\u5206\u53d1\u8bf7\u6c42&#xff0c;\u901a\u8fc7 HandlerMapping \u5339\u914d Controller \u65b9\u6cd5&#xff0c;HandlerAdapter \u8c03\u7528\u65b9\u6cd5&#xff0c;ViewResolver \u89e3\u6790\u89c6\u56fe&#xff1b;<\/li>\n<li>&#064;RequestMapping\u662f\u8bf7\u6c42\u6620\u5c04\u7684\u6838\u5fc3\u6ce8\u89e3&#xff0c;\u652f\u6301\u7c7b\u7ea7\u548c\u65b9\u6cd5\u7ea7\u914d\u7f6e&#xff0c;\u53ef\u6307\u5b9a URL\u3001\u8bf7\u6c42\u65b9\u5f0f\u3001\u53c2\u6570\u7b49&#xff0c;Spring4.3 &#043; \u63d0\u4f9b&#064;GetMapping\/&#064;PostMapping\u7b49\u7b80\u5316\u6ce8\u89e3&#xff1b;<\/li>\n<li>\u89c6\u56fe\u89e3\u6790\u5668\u901a\u8fc7\u524d\u7f00&#xff08;prefix&#xff09;\u548c\u540e\u7f00&#xff08;suffix&#xff09;\u5c06\u89c6\u56fe\u540d\u89e3\u6790\u4e3a\u5177\u4f53\u7684 JSP \u8def\u5f84&#xff0c;\u91cd\u5b9a\u5411\u9700\u52a0redirect:\u524d\u7f00&#xff0c;\u54cd\u5e94 JSON \u9700\u52a0&#064;ResponseBody&#xff1b;<\/li>\n<li>\u6838\u5fc3\u907f\u5751\u70b9&#xff1a;404\/405 \u9519\u8bef\u3001\u9759\u6001\u8d44\u6e90\u8bbf\u95ee\u3001\u4e2d\u6587\u4e71\u7801&#xff0c;\u9700\u91cd\u70b9\u5173\u6ce8\u914d\u7f6e\u6587\u4ef6\u548c\u6ce8\u89e3\u7684\u6b63\u786e\u6027\u3002<\/li>\n<p>\u4e0b\u4e00\u7bc7\u3010Day43\u3011\u9884\u544a&#xff1a;SpringMVC \u53c2\u6570\u7ed1\u5b9a\u4e0e\u8fd4\u56de\u503c\u5904\u7406&#xff1a;\u4ece\u7b80\u5355\u53c2\u6570\u5230\u590d\u6742\u5bf9\u8c61&#xff0c;\u5173\u6ce8\u4e13\u680f\u7ee7\u7eed\u89e3\u9501 SpringMVC \u6838\u5fc3\u529f\u80fd&#xff5e;\u82e5\u672c\u6587\u5bf9\u4f60\u6709\u5e2e\u52a9&#xff0c;\u6b22\u8fce\u70b9\u8d5e &#043; \u6536\u85cf &#043; \u5173\u6ce8&#xff0c;\u4f60\u7684\u652f\u6301\u662f\u6211\u66f4\u65b0\u7684\u6700\u5927\u52a8\u529b&#x1f496;&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6536\u5f55\u4e8e\u300cJava \u5b66\u4e60\u65e5\u8bb0\u300d\u4e13\u680f&#xff0c;\u805a\u7126 SpringMVC \u7684\u6838\u5fc3\u9aa8\u67b6 \u2014\u2014DispatcherServlet \u524d\u7aef\u63a7\u5236\u5668\u4e0e\u8bf7\u6c42\u6620\u5c04\u673a\u5236&#xff0c;\u4ece\u5e95\u5c42\u6d41\u7a0b\u62c6\u89e3\u5230\u6ce8\u89e3\u5f0f\u5b9e\u6218&#xff0c;\u5e2e\u4f60\u6253\u901a SpringMVC \u5165\u95e8\u7684\u5173\u952e\u4e00\u6b65&#xff5e;<br \/>\n\u4e00\u3001\u4e3a\u4ec0\u4e48\u8981\u5b66 SpringMVC&#xff1f;<br \/>\n\u5728\u524d\u5e8f\u7684 Spring \u6838\u5fc3\u5b66\u4e60\u4e2d&#xff0c;\u6211\u4eec\u638c\u63e1\u4e86 IOC\/DI\u3001AOP \u7b49\u57fa\u7840&#xff0c;\u4f46\u5728 Web \u5f00\u53d1\u573a\u666f\u4e0b&#xff0c;\u8fd8\u9762<\/p>\n","protected":false},"author":2,"featured_media":63701,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,1423,190],"topic":[],"class_list":["post-63702","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-mvc","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Day42\u3011SpringMVC \u5165\u95e8\uff1aDispatcherServlet \u4e0e\u8bf7\u6c42\u6620\u5c04 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/63702.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Day42\u3011SpringMVC \u5165\u95e8\uff1aDispatcherServlet \u4e0e\u8bf7\u6c42\u6620\u5c04 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6587\u6536\u5f55\u4e8e\u300cJava \u5b66\u4e60\u65e5\u8bb0\u300d\u4e13\u680f&#xff0c;\u805a\u7126 SpringMVC \u7684\u6838\u5fc3\u9aa8\u67b6 \u2014\u2014DispatcherServlet \u524d\u7aef\u63a7\u5236\u5668\u4e0e\u8bf7\u6c42\u6620\u5c04\u673a\u5236&#xff0c;\u4ece\u5e95\u5c42\u6d41\u7a0b\u62c6\u89e3\u5230\u6ce8\u89e3\u5f0f\u5b9e\u6218&#xff0c;\u5e2e\u4f60\u6253\u901a SpringMVC \u5165\u95e8\u7684\u5173\u952e\u4e00\u6b65&#xff5e; \u4e00\u3001\u4e3a\u4ec0\u4e48\u8981\u5b66 SpringMVC&#xff1f; \u5728\u524d\u5e8f\u7684 Spring \u6838\u5fc3\u5b66\u4e60\u4e2d&#xff0c;\u6211\u4eec\u638c\u63e1\u4e86 IOC\/DI\u3001AOP \u7b49\u57fa\u7840&#xff0c;\u4f46\u5728 Web \u5f00\u53d1\u573a\u666f\u4e0b&#xff0c;\u8fd8\u9762\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/63702.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-22T00:48:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260122004834-697173e2e3c01.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/63702.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/63702.html\",\"name\":\"\u3010Day42\u3011SpringMVC \u5165\u95e8\uff1aDispatcherServlet \u4e0e\u8bf7\u6c42\u6620\u5c04 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-22T00:48:36+00:00\",\"dateModified\":\"2026-01-22T00:48:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/63702.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/63702.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/63702.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Day42\u3011SpringMVC \u5165\u95e8\uff1aDispatcherServlet \u4e0e\u8bf7\u6c42\u6620\u5c04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010Day42\u3011SpringMVC \u5165\u95e8\uff1aDispatcherServlet \u4e0e\u8bf7\u6c42\u6620\u5c04 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/63702.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Day42\u3011SpringMVC \u5165\u95e8\uff1aDispatcherServlet \u4e0e\u8bf7\u6c42\u6620\u5c04 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u672c\u6587\u6536\u5f55\u4e8e\u300cJava \u5b66\u4e60\u65e5\u8bb0\u300d\u4e13\u680f&#xff0c;\u805a\u7126 SpringMVC \u7684\u6838\u5fc3\u9aa8\u67b6 \u2014\u2014DispatcherServlet \u524d\u7aef\u63a7\u5236\u5668\u4e0e\u8bf7\u6c42\u6620\u5c04\u673a\u5236&#xff0c;\u4ece\u5e95\u5c42\u6d41\u7a0b\u62c6\u89e3\u5230\u6ce8\u89e3\u5f0f\u5b9e\u6218&#xff0c;\u5e2e\u4f60\u6253\u901a SpringMVC \u5165\u95e8\u7684\u5173\u952e\u4e00\u6b65&#xff5e; \u4e00\u3001\u4e3a\u4ec0\u4e48\u8981\u5b66 SpringMVC&#xff1f; \u5728\u524d\u5e8f\u7684 Spring \u6838\u5fc3\u5b66\u4e60\u4e2d&#xff0c;\u6211\u4eec\u638c\u63e1\u4e86 IOC\/DI\u3001AOP \u7b49\u57fa\u7840&#xff0c;\u4f46\u5728 Web \u5f00\u53d1\u573a\u666f\u4e0b&#xff0c;\u8fd8\u9762","og_url":"https:\/\/www.wsisp.com\/helps\/63702.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-22T00:48:36+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260122004834-697173e2e3c01.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/63702.html","url":"https:\/\/www.wsisp.com\/helps\/63702.html","name":"\u3010Day42\u3011SpringMVC \u5165\u95e8\uff1aDispatcherServlet \u4e0e\u8bf7\u6c42\u6620\u5c04 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-22T00:48:36+00:00","dateModified":"2026-01-22T00:48:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/63702.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/63702.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/63702.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Day42\u3011SpringMVC \u5165\u95e8\uff1aDispatcherServlet \u4e0e\u8bf7\u6c42\u6620\u5c04"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/63702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=63702"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/63702\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/63701"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=63702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=63702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=63702"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=63702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}