{"id":874,"date":"2023-02-22T20:06:40","date_gmt":"2023-09-20T19:46:27","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/index.php\/2023\/11\/30\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/"},"modified":"2025-08-03T14:29:09","modified_gmt":"2025-08-03T06:29:09","slug":"%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/","title":{"rendered":"Spring RestController\u5b8c\u5168\u6307\u5357\uff1a\u6784\u5efa\u9ad8\u6548RESTful API\u7684\u6700\u4f73\u5b9e\u8df5"},"content":{"rendered":"<p>Spring RestController \u6ce8\u89e3\u662f\u4e00\u4e2a\u65b9\u4fbf\u7684\u6ce8\u89e3\uff0c\u5b83\u672c\u8eab\u5e26\u6709 @Controller \u548c @ResponseBody \u7684\u6ce8\u89e3\u3002\u8be5\u6ce8\u89e3\u5e94\u7528\u4e8e\u7c7b\u4e0a\uff0c\u5c06\u5176\u6807\u8bb0\u4e3a\u8bf7\u6c42\u5904\u7406\u7a0b\u5e8f\u3002Spring RestController \u6ce8\u89e3\u7528\u4e8e\u4f7f\u7528 Spring MVC \u521b\u5efa RESTful Web \u670d\u52a1\u3002Spring RestController \u8d1f\u8d23\u5c06\u8bf7\u6c42\u6570\u636e\u6620\u5c04\u5230\u5b9a\u4e49\u7684\u8bf7\u6c42\u5904\u7406\u7a0b\u5e8f\u65b9\u6cd5\u3002\u4e00\u65e6\u4ece\u5904\u7406\u7a0b\u5e8f\u65b9\u6cd5\u751f\u6210\u54cd\u5e94\u4f53\uff0c\u5b83\u5c06\u5c06\u5176\u8f6c\u6362\u4e3a JSON \u6216 XML \u54cd\u5e94\u3002<\/p>\n<h2>Spring RestController \u793a\u4f8b<\/h2>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fca4b2f92e6c731465\/2-0.png\" alt=\"Spring RestController Example Project\" \/><\/div>\n<h2>Spring RestController Maven\u4f9d\u8d56<\/h2>\n<p>\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u521b\u5efaSpring RestController\u793a\u4f8b\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\u9879\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;dependency&gt;\r\n\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;spring-webmvc&lt;\/artifactId&gt;\r\n\t&lt;version&gt;5.0.7.RELEASE&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;spring-web&lt;\/artifactId&gt;\r\n\t&lt;version&gt;5.0.7.RELEASE&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n\r\n&lt;!-- Jackson for REST JSON Support --&gt;\r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;jackson-databind&lt;\/artifactId&gt;\r\n\t&lt;version&gt;2.9.6&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n&lt;!-- JAXB for XML Response, needed to explicitly define from Java 9 onwards --&gt;\r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;javax.xml.bind&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;jaxb-api&lt;\/artifactId&gt;\r\n\t&lt;version&gt;2.3.0&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;org.glassfish.jaxb&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;jaxb-runtime&lt;\/artifactId&gt;\r\n\t&lt;version&gt;2.3.0&lt;\/version&gt;\r\n\t&lt;scope&gt;runtime&lt;\/scope&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;javax.activation&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;javax.activation-api&lt;\/artifactId&gt;\r\n\t&lt;version&gt;1.2.0&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n<\/code><\/pre>\n<p>\u6211\u4eec\u9700\u8981Spring MVC\u3001Jackson\u548cJAXB\u5e93\u6765\u652f\u6301\u6211\u4eec\u7684REST Web\u670d\u52a1\u5bf9XML\u548cJSON\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u5904\u7406\u3002\u6211\u4eec\u4f7f\u7528web.xml\u6587\u4ef6\u6765\u914d\u7f6eSpring MVC\u7684DispatcherServlet\u4f5c\u4e3a\u524d\u7aef\u63a7\u5236\u5668\u3002\u73b0\u5728\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u4e0bSpring\u4e0a\u4e0b\u6587\u6587\u4ef6\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans:beans\r\n\txmlns=\"https:\/\/www.springframework.org\/schema\/mvc\"\r\n\txmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txmlns:beans=\"https:\/\/www.springframework.org\/schema\/beans\"\r\n\txmlns:context=\"https:\/\/www.springframework.org\/schema\/context\"\r\n\txsi:schemaLocation=\"https:\/\/www.springframework.org\/schema\/mvc https:\/\/www.springframework.org\/schema\/mvc\/spring-mvc.xsd\r\n\t\thttps:\/\/www.springframework.org\/schema\/beans https:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\r\n\t\thttps:\/\/www.springframework.org\/schema\/context https:\/\/www.springframework.org\/schema\/context\/spring-context.xsd\"&gt;\r\n\r\n\t&lt;!-- Enables the Spring MVC @Controller programming model --&gt;\r\n\t&lt;annotation-driven \/&gt;\r\n\r\n\t&lt;context:component-scan\r\n\t\tbase-package=\"com.Olivia.spring\" \/&gt;\r\n\r\n\t&lt;beans:bean id=\"jsonMessageConverter\"\r\n\t\tclass=\"org.springframework.http.converter.json.MappingJackson2HttpMessageConverter\" \/&gt;\r\n\t&lt;beans:bean id=\"xmlMessageConverter\"\r\n\t\tclass=\"org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter\" \/&gt;\r\n\r\n\t&lt;beans:bean\r\n\t\tclass=\"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter\"&gt;\r\n\t\t&lt;beans:property name=\"messageConverters\"&gt;\r\n\t\t\t&lt;beans:list&gt;\r\n\t\t\t\t&lt;beans:ref bean=\"jsonMessageConverter\" \/&gt;\r\n\t\t\t\t&lt;beans:ref bean=\"xmlMessageConverter\" \/&gt;\r\n\t\t\t&lt;\/beans:list&gt;\r\n\t\t&lt;\/beans:property&gt;\r\n\t&lt;\/beans:bean&gt;\r\n\r\n&lt;\/beans:beans&gt;\r\n<\/code><\/pre>\n<p>\u6700\u91cd\u8981\u7684\u90e8\u5206\u662f\u5728RequestMappingHandlerAdapter\u4e2d\u5b9a\u4e49\u548c\u8bbe\u7f6e\u7684jsonMessageConverter\u548cxmlMessageConverter beans\uff0c\u901a\u8fc7messageConverters\u5c5e\u6027\u544a\u8bc9Spring\u6211\u4eec\u5e0c\u671b\u5e94\u7528\u7a0b\u5e8f\u652f\u6301JSON\u548cXML\uff0c\u5e76\u4f7f\u7528\u8fd9\u4e9bbeans\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n<h2>\u6625\u5b63\u7684RestController\u7c7b<\/h2>\n<p>\u8fd9\u662f\u6211\u4eec\u7684Spring RestController\u7c7b\u7684\u5b9e\u73b0\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.spring.controller;\r\n\r\nimport java.util.List;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.web.bind.annotation.DeleteMapping;\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.PathVariable;\r\nimport org.springframework.web.bind.annotation.PostMapping;\r\nimport org.springframework.web.bind.annotation.RequestBody;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\nimport com.Olivia.spring.model.Employee;\r\nimport com.Olivia.spring.repository.EmployeeRepository;\r\n\r\n@RestController\r\npublic class EmployeeRestController {\r\n\r\n\t@Autowired\r\n\tprivate EmployeeRepository repository;\r\n\t\r\n\t@GetMapping(\"\/rest\/employee\/get\/{id}\")\r\n\tpublic Employee getEmployeeByID(@PathVariable(\"id\") int id) {\r\n\t\treturn repository.retrieve(id);\r\n\t}\r\n\t\r\n\t@GetMapping(\"\/rest\/employee\/getAll\")\r\n\t\/\/Returning is List is supported with JSON response only\r\n\t\/\/If you want XML, then add a wrapper class as Root XML element, for example EmployeeList\r\n\tpublic List&lt;Employee&gt; getAllEmployees() {\r\n\t\treturn repository.getAll();\r\n\t}\r\n\r\n\t@PostMapping(\"\/rest\/employee\/create\")\r\n\tpublic Employee createEmployee(@RequestBody Employee emp) {\r\n\t\trepository.store(emp);\r\n\t\treturn emp;\r\n\t}\r\n\t\r\n\t@GetMapping(\"\/rest\/employee\/search\/{name}\")\r\n\tpublic Employee getEmployeeByName(@PathVariable(\"name\") String name) {\r\n\t\treturn repository.search(name);\r\n\t}\r\n\t\r\n\t@DeleteMapping(\"\/rest\/employee\/delete\/{id}\")\r\n\tpublic Employee deleteEmployeeByID(@PathVariable(\"id\") int id) {\r\n\t\treturn repository.delete(id);\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u8fd9\u91cc\u53ea\u5b9a\u4e49\u4e86\u6211\u4eec\u7684REST API\uff0c\u6240\u6709\u7684\u4e1a\u52a1\u903b\u8f91\u90fd\u662fRepository\u7c7b\u7684\u4e00\u90e8\u5206\u3002\u5982\u679c\u6211\u4eec\u7684\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\u6216\u6570\u7ec4\uff0c\u90a3\u4e48Spring\u53ea\u652f\u6301JSON\u54cd\u5e94\uff0c\u56e0\u4e3aXML\u7684\u6839\u5143\u7d20\u4e0d\u80fd\u662f\u533f\u540d\u7684\uff0c\u4f46JSON\u53ef\u4ee5\u3002\u5982\u679c\u4f60\u60f3\u652f\u6301\u5c06\u5217\u8868\u4f5c\u4e3aXML\u8fd4\u56de\uff0c\u90a3\u4e48\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5305\u88c5\u7c7b\u6765\u5bb9\u7eb3\u8fd9\u4e2a\u5217\u8868\u5e76\u8fd4\u56de\u5b83\u3002\u5728\u67d0\u4e9b\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u671f\u671b\u8bf7\u6c42\u7684\u662f\u5458\u5de5\u5bf9\u8c61\uff0cSpring\u4f1a\u8d1f\u8d23\u89e3\u6790\u8bf7\u6c42\u4f53\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u5458\u5de5\u5bf9\u8c61\u3002\u540c\u6837\u5730\uff0c\u6211\u4eec\u5c06\u5458\u5de5\u5bf9\u8c61\u4f5c\u4e3a\u54cd\u5e94\u4f53\u8fd4\u56de\uff0cSpring\u4f1a\u8d1f\u8d23\u5c06\u5176\u8f6c\u6362\u4e3aJSON\/XML\u54cd\u5e94\u3002<\/p>\n<h2>\u63a5\u53d7\u548c\u5185\u5bb9\u7c7b\u578b\u7684\u8bf7\u6c42\u5934<\/h2>\n<p>\u6211\u4eec\u5df2\u7ecf\u914d\u7f6e\u4e86\u6211\u4eec\u7684REST\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f7f\u5176\u80fd\u591f\u4e0eXML\u548cJSON\u4e00\u8d77\u5de5\u4f5c\u3002\u90a3\u4e48\u5b83\u5c06\u5982\u4f55\u77e5\u9053\u8bf7\u6c42\u662fXML\u8fd8\u662fJSON\u5462\uff1f\u5982\u679c\u54cd\u5e94\u5e94\u4ee5JSON\u6216XML\u683c\u5f0f\u53d1\u9001\u3002\u8fd9\u5c31\u662f\u4f7f\u7528Accept\u548cContent-Type\u8bf7\u6c42\u5934\u7684\u5730\u65b9\u3002Content-Type\uff1a\u5b9a\u4e49\u4e86\u8bf7\u6c42\u4f53\u4e2d\u7684\u5185\u5bb9\u7c7b\u578b\uff0c\u5982\u679c\u503c\u4e3a\u201capplication\/xml\u201d\uff0c\u5219Spring\u5c06\u5c06\u8bf7\u6c42\u4f53\u89c6\u4e3aXML\u6587\u6863\u3002\u5982\u679c\u5b83\u7684\u503c\u662f\u201capplication\/json\u201d\uff0c\u5219\u8bf7\u6c42\u4f53\u5c06\u88ab\u89c6\u4e3aJSON\u3002Accept\uff1a\u5b9a\u4e49\u4e86\u5ba2\u6237\u7aef\u671f\u671b\u7684\u54cd\u5e94\u5185\u5bb9\u7c7b\u578b\u3002\u5982\u679c\u503c\u4e3a\u201capplication\/xml\u201d\uff0c\u5219\u5c06\u53d1\u9001XML\u54cd\u5e94\u3002\u5982\u679c\u5176\u503c\u4e3a\u201capplication\/json\u201d\uff0c\u5219\u5c06\u53d1\u9001JSON\u54cd\u5e94\u3002<\/p>\n<h2>Spring RestController \u6d4b\u8bd5<\/h2>\n<p>\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u5df2\u7ecf\u51c6\u5907\u597d\u8fdb\u884c\u6d4b\u8bd5\u4e86\uff0c\u6211\u5df2\u7ecf\u90e8\u7f72\u5728Tomcat-9\u4e0a\u5e76\u4e14\u6b63\u5728\u4f7f\u7528Postman\u8fdb\u884c\u6d4b\u8bd5\u3002\u4ee5\u4e0b\u662f\u6d4b\u8bd5\u7ed3\u679c\u53ca\u89e3\u91ca\u3002<\/p>\n<h3>\u4f7f\u7528Spring\u7684RestController\u8fd4\u56deJSON\u54cd\u5e94<\/h3>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fca4b2f92e6c731465\/18-0.png\" alt=\"Spring RestController GET JSON Response\" \/><\/div>\n<h3>Spring\u7684RestController\u4f7f\u7528GET\u65b9\u5f0f\u8fd4\u56deXML\u54cd\u5e94<\/h3>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fca4b2f92e6c731465\/20-0.png\" alt=\"Spring REST XML Response Accept header\" \/><\/div>\n<h3>\u6625\u5929 RestController GET \u5217\u8868<\/h3>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fca4b2f92e6c731465\/22-1.png\" alt=\"Spring REST GET List XML\" \/><\/div>\n<h3>\u6625\u5b63 RestController \u7684 POST \u65b9\u6cd5<\/h3>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fca4b2f92e6c731465\/24-2.png\" alt=\"Spring RestController POST JSON Request and XML Response\" \/><\/div>\n<h3>\u6625\u5929\u7684RestController \u5220\u9664<\/h3>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fca4b2f92e6c731465\/26-1.png\" alt=\"Spring RestController DELETE XML Response\" \/><\/div>\n<h2>Summary (Chinese): \u6982\u62ec<\/h2>\n<p>Spring RestController\u901a\u8fc7\u5904\u7406\u6240\u6709\u7e41\u7410\u7684\u5de5\u4f5c\u6765\u5e2e\u52a9\u6211\u4eec\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91\uff0c\u4ee5\u4fbf\u521b\u5efaREST Web\u670d\u52a1APIs\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u4ece\u6211\u4eec\u7684 GitHub \u5b58\u50a8\u5e93\u4e0b\u8f7d\u5b8c\u6574\u7684\u9879\u76ee\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring RestController \u6ce8\u89e3\u662f\u4e00\u4e2a\u65b9\u4fbf\u7684\u6ce8\u89e3\uff0c\u5b83\u672c\u8eab\u5e26\u6709 @Controller \u548c @R [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[761,2275,1174,1089,323],"class_list":["post-874","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-java","tag-restcontroller","tag-restful-api","tag-spring","tag-web"],"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>Spring RestController\u5b8c\u5168\u6307\u5357\uff1a\u6784\u5efa\u9ad8\u6548RESTful API\u7684\u6700\u4f73\u5b9e\u8df5 - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"\u6df1\u5165\u4e86\u89e3Spring RestController\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u672c\u6307\u5357\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528RestController\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u7684RESTful API\uff0c\u5305\u62ec\u8bf7\u6c42\u5904\u7406\u3001\u6570\u636e\u7ed1\u5b9a\u3001\u5f02\u5e38\u5904\u7406\u7b49\u6838\u5fc3\u6982\u5ff5\u3002\" \/>\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\/\u6625\u5929\u7684restcontroller\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring RestController\u5b8c\u5168\u6307\u5357\uff1a\u6784\u5efa\u9ad8\u6548RESTful API\u7684\u6700\u4f73\u5b9e\u8df5\" \/>\n<meta property=\"og:description\" content=\"\u6df1\u5165\u4e86\u89e3Spring RestController\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u672c\u6307\u5357\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528RestController\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u7684RESTful API\uff0c\u5305\u62ec\u8bf7\u6c42\u5904\u7406\u3001\u6570\u636e\u7ed1\u5b9a\u3001\u5f02\u5e38\u5904\u7406\u7b49\u6838\u5fc3\u6982\u5ff5\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u6625\u5929\u7684restcontroller\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-20T19:46:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-03T06:29:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fca4b2f92e6c731465\/2-0.png\" \/>\n<meta name=\"author\" content=\"\u6e05, \u5b87\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u5b87\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/\",\"name\":\"Spring RestController\u5b8c\u5168\u6307\u5357\uff1a\u6784\u5efa\u9ad8\u6548RESTful API\u7684\u6700\u4f73\u5b9e\u8df5 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-09-20T19:46:27+00:00\",\"dateModified\":\"2025-08-03T06:29:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e\"},\"description\":\"\u6df1\u5165\u4e86\u89e3Spring RestController\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u672c\u6307\u5357\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528RestController\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u7684RESTful API\uff0c\u5305\u62ec\u8bf7\u6c42\u5904\u7406\u3001\u6570\u636e\u7ed1\u5b9a\u3001\u5f02\u5e38\u5904\u7406\u7b49\u6838\u5fc3\u6982\u5ff5\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring RestController\u5b8c\u5168\u6307\u5357\uff1a\u6784\u5efa\u9ad8\u6548RESTful API\u7684\u6700\u4f73\u5b9e\u8df5\"}]},{\"@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\/1a6ecd3d914d22a5ac32791ffc1fbd8e\",\"name\":\"\u6e05, \u5b87\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u5b87\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Spring RestController\u5b8c\u5168\u6307\u5357\uff1a\u6784\u5efa\u9ad8\u6548RESTful API\u7684\u6700\u4f73\u5b9e\u8df5 - Blog - Silicon Cloud","description":"\u6df1\u5165\u4e86\u89e3Spring RestController\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u672c\u6307\u5357\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528RestController\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u7684RESTful API\uff0c\u5305\u62ec\u8bf7\u6c42\u5904\u7406\u3001\u6570\u636e\u7ed1\u5b9a\u3001\u5f02\u5e38\u5904\u7406\u7b49\u6838\u5fc3\u6982\u5ff5\u3002","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\/\u6625\u5929\u7684restcontroller\/","og_locale":"zh_CN","og_type":"article","og_title":"Spring RestController\u5b8c\u5168\u6307\u5357\uff1a\u6784\u5efa\u9ad8\u6548RESTful API\u7684\u6700\u4f73\u5b9e\u8df5","og_description":"\u6df1\u5165\u4e86\u89e3Spring RestController\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u672c\u6307\u5357\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528RestController\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u7684RESTful API\uff0c\u5305\u62ec\u8bf7\u6c42\u5904\u7406\u3001\u6570\u636e\u7ed1\u5b9a\u3001\u5f02\u5e38\u5904\u7406\u7b49\u6838\u5fc3\u6982\u5ff5\u3002","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u6625\u5929\u7684restcontroller\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-09-20T19:46:27+00:00","article_modified_time":"2025-08-03T06:29:09+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fca4b2f92e6c731465\/2-0.png"}],"author":"\u6e05, \u5b87","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u5b87","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/","name":"Spring RestController\u5b8c\u5168\u6307\u5357\uff1a\u6784\u5efa\u9ad8\u6548RESTful API\u7684\u6700\u4f73\u5b9e\u8df5 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-09-20T19:46:27+00:00","dateModified":"2025-08-03T06:29:09+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e"},"description":"\u6df1\u5165\u4e86\u89e3Spring RestController\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u672c\u6307\u5357\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528RestController\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u7684RESTful API\uff0c\u5305\u62ec\u8bf7\u6c42\u5904\u7406\u3001\u6570\u636e\u7ed1\u5b9a\u3001\u5f02\u5e38\u5904\u7406\u7b49\u6838\u5fc3\u6982\u5ff5\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"Spring RestController\u5b8c\u5168\u6307\u5357\uff1a\u6784\u5efa\u9ad8\u6548RESTful API\u7684\u6700\u4f73\u5b9e\u8df5"}]},{"@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\/1a6ecd3d914d22a5ac32791ffc1fbd8e","name":"\u6e05, \u5b87","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","caption":"\u6e05, \u5b87"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%98%a5%e5%a4%a9%e7%9a%84restcontroller\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/874","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=874"}],"version-history":[{"count":4,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/874\/revisions"}],"predecessor-version":[{"id":110839,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/874\/revisions\/110839"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}