{"id":11582,"date":"2023-11-28T22:26:37","date_gmt":"2023-11-28T14:26:37","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=11582"},"modified":"2023-12-11T11:24:23","modified_gmt":"2023-12-11T03:24:23","slug":"springmvc-kuang-jia-de-kong-zhi-qi-shi-shen-me","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/springmvc-kuang-jia-de-kong-zhi-qi-shi-shen-me\/","title":{"rendered":"SpringMVC\u6846\u67b6\u7684\u63a7\u5236\u5668\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p>\u5728SpringMVC\u6846\u67b6\u4e2d\uff0c\u63a7\u5236\u5668\uff08Controller\uff09\u662f\u8d1f\u8d23\u5904\u7406\u7528\u6237\u8bf7\u6c42\u7684\u7ec4\u4ef6\uff0c\u5b83\u63a5\u6536\u7528\u6237\u7684\u8f93\u5165\uff0c\u8c03\u7528\u4e1a\u52a1\u903b\u8f91\u8fdb\u884c\u5904\u7406\uff0c\u5e76\u6700\u7ec8\u8fd4\u56de\u7ed3\u679c\u7ed9\u7528\u6237\u3002\u63a7\u5236\u5668\u662fSpringMVC\u4e2d\u7684\u6838\u5fc3\u7ec4\u4ef6\u4e4b\u4e00\uff0c\u8d77\u5230\u8fde\u63a5\u89c6\u56fe\u548c\u6a21\u578b\u7684\u4f5c\u7528\u3002<\/p>\n<p>\u5728SpringMVC\u4e2d\uff0c\u63a7\u5236\u5668\u53ef\u4ee5\u4f7f\u7528<code>@Controller<\/code>\u6ce8\u89e3\u6765\u6807\u8bc6\uff0c\u5e76\u901a\u8fc7\u65b9\u6cd5\u7ea7\u522b\u7684<code>@RequestMapping<\/code>\u6ce8\u89e3\u6765\u6620\u5c04\u8bf7\u6c42\u8def\u5f84\u3002\u63a7\u5236\u5668\u8d1f\u8d23\u63a5\u6536\u8bf7\u6c42\u53c2\u6570\u3001\u8c03\u7528\u4e1a\u52a1\u903b\u8f91\uff0c\u7136\u540e\u8fd4\u56de\u89c6\u56fe\u6216\u6570\u636e\u7ed9\u7528\u6237\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684SpringMVC\u63a7\u5236\u5668\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-java\">import org.springframework.stereotype.Controller;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport org.springframework.ui.Model;\n\n@Controller\n@RequestMapping(&quot;\/example&quot;)\npublic class MyController {\n\n    @RequestMapping(value = &quot;\/hello&quot;, method = RequestMethod.GET)\n    public String hello(Model model) {\n        model.addAttribute(&quot;message&quot;, &quot;Hello, SpringMVC!&quot;);\n        return &quot;helloPage&quot;; \/\/ \u89c6\u56fe\u7684\u903b\u8f91\u540d\u79f0\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>MyController<\/code> \u7c7b\u88ab\u6807\u8bc6\u4e3a\u4e00\u4e2a\u63a7\u5236\u5668\uff0c\u901a\u8fc7<code>@RequestMapping(&quot;\/example&quot;)<\/code>\u6307\u5b9a\u4e86\u63a7\u5236\u5668\u7684\u6839\u8def\u5f84\u3002<code>hello<\/code>\u65b9\u6cd5\u5904\u7406GET\u8bf7\u6c42\uff0c\u5e76\u4f7f\u7528<code>model.addAttribute<\/code>\u5411\u89c6\u56fe\u4f20\u9012\u6570\u636e\u3002\u8be5\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32 <code>&quot;helloPage&quot;<\/code>\uff0c\u8fd9\u662f\u89c6\u56fe\u7684\u903b\u8f91\u540d\u79f0\uff0cSpringMVC\u5c06\u4f1a\u6839\u636e\u89c6\u56fe\u89e3\u6790\u5668\u627e\u5230\u76f8\u5e94\u7684\u89c6\u56fe\u3002<\/p>\n<p>\u63a7\u5236\u5668\u7684\u4e3b\u8981\u4f5c\u7528\u5305\u62ec\uff1a<\/p>\n<ol>\n<li><strong>\u5904\u7406\u7528\u6237\u8bf7\u6c42\uff1a<\/strong> \u901a\u8fc7<code>@RequestMapping<\/code>\u7b49\u6ce8\u89e3\u5b9a\u4e49\u5904\u7406\u8bf7\u6c42\u7684\u65b9\u6cd5\u3002<\/li>\n<li><strong>\u8c03\u7528\u4e1a\u52a1\u903b\u8f91\uff1a<\/strong> \u63a7\u5236\u5668\u8d1f\u8d23\u8c03\u7528\u670d\u52a1\u5c42\uff08Service\uff09\u6216\u5176\u4ed6\u4e1a\u52a1\u903b\u8f91\u7ec4\u4ef6\u6765\u5904\u7406\u4e1a\u52a1\u3002<\/li>\n<li><strong>\u4f20\u9012\u6570\u636e\u5230\u89c6\u56fe\uff1a<\/strong> \u4f7f\u7528<code>Model<\/code>\u5bf9\u8c61\u4f20\u9012\u6570\u636e\u5230\u89c6\u56fe\uff0c\u4ee5\u4fbf\u6e32\u67d3\u9875\u9762\u3002<\/li>\n<li><strong>\u9009\u62e9\u89c6\u56fe\uff1a<\/strong> \u8fd4\u56de\u89c6\u56fe\u7684\u903b\u8f91\u540d\u79f0\uff0c\u7531\u89c6\u56fe\u89e3\u6790\u5668\u89e3\u6790\u4e3a\u5177\u4f53\u7684\u89c6\u56fe\u3002<\/li>\n<\/ol>\n<p>SpringMVC\u7684\u63a7\u5236\u5668\u5c42\u4e0e\u89c6\u56fe\u5c42\u548c\u6a21\u578b\u5c42\u89e3\u8026\uff0c\u5b9e\u73b0\u4e86\u677e\u8026\u5408\u7684\u67b6\u6784\uff0c\u4f7f\u5f97\u7cfb\u7edf\u66f4\u6613\u4e8e\u7ef4\u62a4\u548c\u6269\u5c55\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728SpringMVC\u6846\u67b6\u4e2d\uff0c\u63a7\u5236\u5668\uff08Controller\uff09\u662f\u8d1f\u8d23\u5904\u7406\u7528\u6237\u8bf7\u6c42\u7684\u7ec4\u4ef6\uff0c\u5b83\u63a5\u6536\u7528\u6237\u7684\u8f93\u5165\uff0c\u8c03\u7528\u4e1a\u52a1 [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121],"tags":[],"class_list":["post-11582","post","type-post","status-publish","format-standard","hentry","category-spring"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=11582"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11582\/revisions"}],"predecessor-version":[{"id":17084,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11582\/revisions\/17084"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=11582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=11582"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=11582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}