{"id":39978,"date":"2022-07-11T03:30:07","date_gmt":"2023-08-16T18:19:00","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/"},"modified":"2024-01-15T10:27:30","modified_gmt":"2024-01-15T02:27:30","slug":"%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/","title":{"rendered":"\u5173\u4e8e Spring Boot \u7684\u6ce8\u89e3\uff08@RequestParam\uff09"},"content":{"rendered":"<p>\u7531\u65bc\u6700\u8fd1\u5728\u5b78\u7fd2Spring Boot\uff0c\u7279\u5225\u91cd\u65b0\u5b78\u7fd2\u4e86\u57fa\u790e\u8a3b\u89e3\u4e2d\u7684@RequestParam\uff0c\u56e0\u6b64\u6211\u4e5f\u5c07\u5b78\u7fd2\u6210\u679c\u6574\u7406\u6210\u7b46\u8a18\u3002<\/p>\n<h2>RequestParam \u8bf7\u6c42\u53c2\u6570<\/h2>\n<p>\u2460RequestParam \u7528\u4e8e\u8bf7\u6c42\u53c2\u6570<\/p>\n<p>\u901a\u8fc7\u6d4f\u89c8\u5668\u8bf7\u6c42\u53ef\u4ee5\u83b7\u53d6\u503c\uff08\u53c2\u6570\uff09\u7684\u6ce8\u89e3\u3002<\/p>\n<h3>\u63a7\u5236\u5668\u7c7b (Kongzhiqi class)<\/h3>\n<pre class=\"post-pre\"><code>\r\n<span class=\"kd\">public<\/span> <span class=\"nc\">String<\/span> <span class=\"nf\">example<\/span><span class=\"o\">(<\/span><span class=\"nd\">@RequestParam<\/span><span class=\"o\">(<\/span><span class=\"s\">\"message\"<\/span><span class=\"o\">)<\/span><span class=\"nc\">String<\/span> <span class=\"n\">message<\/span> <span class=\"nc\">Model<\/span> <span class=\"n\">model<\/span> <span class=\"o\">)<\/span> <span class=\"o\">{<\/span>\r\n\r\n<span class=\"nc\">Model<\/span><span class=\"o\">.<\/span><span class=\"na\">attribute<\/span><span class=\"o\">(<\/span><span class=\"s\">\"message\"<\/span><span class=\"o\">,<\/span> <span class=\"n\">message<\/span><span class=\"o\">);<\/span>\r\n\r\n<span class=\"k\">return<\/span> <span class=\"s\">\"example\"<\/span><span class=\"o\">;<\/span>\r\n\r\n<span class=\"o\">}<\/span>\r\n\r\n<\/code><\/pre>\n<h3>\u67e5\u770b\uff08HTML\uff09<\/h3>\n<pre class=\"post-pre\"><code><span class=\"nt\">&lt;p<\/span> <span class=\"na\">th:text = <\/span><span class=\"s\">\u201c${message}\u201d<\/span><span class=\"nt\">&gt;&lt;\/p&gt;<\/span>\r\n<\/code><\/pre>\n<p>\u5728\u53d1\u9001\u8bf7\u6c42\u65f6\uff0c\u5982\u4e0b\u6240\u793a\uff1ahttp:\/\/localhost:8080\/~?message=example<\/p>\n<blockquote><p>\u6d88\u606f = \u4f8b\u5b50 =<\/p><\/blockquote>\n<p>\u901a\u8fc7\u505a\u4ee5\u4e0b\u64cd\u4f5c\uff0c<br \/>\n\u2460 &#8220;message&#8221; \u7684 RequestParam \u88ab\u8d4b\u4e88\u5b57\u7b26\u4e32 &#8220;example&#8221;\u3002<\/p>\n<p>\u2461\u5b57\u7b26\u4e32\u4fe1\u606f\u4e3aexample\u3002<\/p>\n<p>\u2462\u5728th:text =\u201c${message}\u201d\u4e2d\uff0c\u5728html\u6587\u4ef6\u4e2d\u5c06\u663e\u793a\u4e3aexample\u3002<\/p>\n<h2>\u53d8\u91cf\u7684\u7701\u7565<\/h2>\n<p>\u5982\u679cRequestParam\u53d8\u91cf\u540d\u4e0e\u76f8\u5173\u8054\u7684\u53c2\u6570\u53d8\u91cf\u76f8\u540c\uff0c\u5219\u53ef\u4ee5\u7701\u7565\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"nd\">@RequestParam<\/span><span class=\"o\">(<\/span><span class=\"s\">\"message\"<\/span><span class=\"o\">)<\/span><span class=\"nc\">String<\/span> <span class=\"n\">message<\/span>\r\n\r\n<span class=\"nd\">@RequestParam<\/span> <span class=\"nc\">String<\/span> <span class=\"n\">message<\/span>\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f7f\u7528\u4e86RequestParam\uff0c\u5219\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u9700\u8981\u8f93\u5165\u503c\uff0c\u5426\u5219\u4f1a\u4ea7\u751f\u9519\u8bef\u3002<\/p>\n<p>\u5728\u4f7f\u7528@RequestParam (&#8220;message&#8221;) String message\u7684\u60c5\u51b5\u4e0b\uff0c<\/p>\n<p>http:\/\/localhost:8080\/ \u53ea\u662f\uff08\u6ca1\u6709\u4f20\u9012\u4efb\u4f55\u503c\u4f5c\u4e3a\u53c2\u6570\uff09\u800c\u4e14\u53d1\u751f\u9519\u8bef\u3002<\/p>\n<p>\u4e3a\u4e86\u907f\u514d\u51fa\u73b0\u9519\u8bef\uff0c\u9700\u8981\u5c06 &#8220;required = false&#8221; \u8bbe\u7f6e\u4e3a false\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"nd\">@RequestParam<\/span><span class=\"o\">(<\/span><span class=\"n\">required<\/span> <span class=\"o\">=<\/span> <span class=\"kc\">false<\/span><span class=\"o\">)<\/span>\r\n<\/code><\/pre>\n<p>\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"nd\">@RequestParam<\/span> <span class=\"o\">(<\/span><span class=\"n\">defaultValue<\/span> <span class=\"o\">=<\/span> <span class=\"s\">\"hello\"<\/span><span class=\"o\">)<\/span> <span class=\"nc\">String<\/span> <span class=\"n\">message<\/span>\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7531\u65bc\u6700\u8fd1\u5728\u5b78\u7fd2Spring Boot\uff0c\u7279\u5225\u91cd\u65b0\u5b78\u7fd2\u4e86\u57fa\u790e\u8a3b\u89e3\u4e2d\u7684@RequestParam\uff0c\u56e0\u6b64\u6211\u4e5f\u5c07\u5b78\u7fd2\u6210\u679c [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-39978","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5173\u4e8e Spring Boot \u7684\u6ce8\u89e3\uff08@RequestParam\uff09 - Blog - Silicon Cloud<\/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.silicloud.com\/zh\/blog\/\u5173\u4e8e-spring-boot-\u7684\u6ce8\u89e3\uff08requestparam\uff09\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5173\u4e8e Spring Boot \u7684\u6ce8\u89e3\uff08@RequestParam\uff09\" \/>\n<meta property=\"og:description\" content=\"\u7531\u65bc\u6700\u8fd1\u5728\u5b78\u7fd2Spring Boot\uff0c\u7279\u5225\u91cd\u65b0\u5b78\u7fd2\u4e86\u57fa\u790e\u8a3b\u89e3\u4e2d\u7684@RequestParam\uff0c\u56e0\u6b64\u6211\u4e5f\u5c07\u5b78\u7fd2\u6210\u679c [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5173\u4e8e-spring-boot-\u7684\u6ce8\u89e3\uff08requestparam\uff09\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-16T18:19:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-15T02:27:30+00:00\" \/>\n<meta name=\"author\" content=\"\u65b0, \u97f5\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u65b0, \u97f5\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/\",\"name\":\"\u5173\u4e8e Spring Boot \u7684\u6ce8\u89e3\uff08@RequestParam\uff09 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-08-16T18:19:00+00:00\",\"dateModified\":\"2024-01-15T02:27:30+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/4ba4019495123db3038fd0809e6959c9\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5173\u4e8e Spring Boot \u7684\u6ce8\u89e3\uff08@RequestParam\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/4ba4019495123db3038fd0809e6959c9\",\"name\":\"\u65b0, \u97f5\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d484b6c6e4ae82e8a9efea989e1d2af46d9b6ef128101e63b18f559fca0ae627?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d484b6c6e4ae82e8a9efea989e1d2af46d9b6ef128101e63b18f559fca0ae627?s=96&d=mm&r=g\",\"caption\":\"\u65b0, \u97f5\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunxin\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u5173\u4e8e Spring Boot \u7684\u6ce8\u89e3\uff08@RequestParam\uff09 - Blog - Silicon Cloud","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.silicloud.com\/zh\/blog\/\u5173\u4e8e-spring-boot-\u7684\u6ce8\u89e3\uff08requestparam\uff09\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5173\u4e8e Spring Boot \u7684\u6ce8\u89e3\uff08@RequestParam\uff09","og_description":"\u7531\u65bc\u6700\u8fd1\u5728\u5b78\u7fd2Spring Boot\uff0c\u7279\u5225\u91cd\u65b0\u5b78\u7fd2\u4e86\u57fa\u790e\u8a3b\u89e3\u4e2d\u7684@RequestParam\uff0c\u56e0\u6b64\u6211\u4e5f\u5c07\u5b78\u7fd2\u6210\u679c [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5173\u4e8e-spring-boot-\u7684\u6ce8\u89e3\uff08requestparam\uff09\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-08-16T18:19:00+00:00","article_modified_time":"2024-01-15T02:27:30+00:00","author":"\u65b0, \u97f5","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u65b0, \u97f5"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/","name":"\u5173\u4e8e Spring Boot \u7684\u6ce8\u89e3\uff08@RequestParam\uff09 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-08-16T18:19:00+00:00","dateModified":"2024-01-15T02:27:30+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/4ba4019495123db3038fd0809e6959c9"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u5173\u4e8e Spring Boot \u7684\u6ce8\u89e3\uff08@RequestParam\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/4ba4019495123db3038fd0809e6959c9","name":"\u65b0, \u97f5","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d484b6c6e4ae82e8a9efea989e1d2af46d9b6ef128101e63b18f559fca0ae627?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d484b6c6e4ae82e8a9efea989e1d2af46d9b6ef128101e63b18f559fca0ae627?s=96&d=mm&r=g","caption":"\u65b0, \u97f5"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunxin\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%85%b3%e4%ba%8e-spring-boot-%e7%9a%84%e6%b3%a8%e8%a7%a3%ef%bc%88requestparam%ef%bc%89\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/39978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=39978"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/39978\/revisions"}],"predecessor-version":[{"id":58619,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/39978\/revisions\/58619"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=39978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=39978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=39978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}