{"id":8582,"date":"2022-11-17T13:52:51","date_gmt":"2022-11-17T05:52:51","guid":{"rendered":"http:\/\/123.57.164.21\/?p=8582"},"modified":"2022-11-17T13:52:51","modified_gmt":"2022-11-17T05:52:51","slug":"requestmapping-%e4%b8%adproduces-%e5%92%8c-consumes","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=8582","title":{"rendered":"RequestMapping \u4e2dproduces \u548c consumes"},"content":{"rendered":"\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\uff0c\u7ecf\u5e38\u5173\u6ce8\u6838\u5fc3\u7684\u4e1a\u52a1\u6216\u8005\u6838\u5fc3\u7684\u67b6\u6784\u624b\u6cd5\uff0c\u5f80\u5f80\u5ffd\u7565\u4e86\u4e00\u4e9b\u5c0f\u7684\u70b9\u70b9\u6ef4\u6ef4<br>\u4eca\u5929\u5c31\u8bb0\u5f55\u4e0b\u5728SpringBoot\u5f00\u53d1\u4e2d @RequestMapping \u6ce8\u89e3\u4e2d\u7684\u5e38\u89c1\u53c2\u6570\u7b80\u5355\u8bf4\u660e\u3002<\/p>\n\n\n\n<p>\u8bf4\u5230\u8fd9\u4e24\u4e2a\u53c2\u6570\uff0c\u4e0d\u5f97\u4e0d\u5148\u56de\u987e\u4e00\u4e0bHTTP\u534f\u8baeHeader\u4e2d\u7684\u4e24\u4e2a\u4e1c\u897f ContentType \u548cAccept\u3002<\/p>\n\n\n\n<ul><li>ContentType\uff1a \u544a\u8bc9\u670d\u52a1\u5668\u5f53\u524d\u53d1\u9001\u7684\u6570\u636e\u662f\u4ec0\u4e48\u683c\u5f0f<\/li><li>Accept \uff1a \u7528\u6765\u544a\u8bc9\u670d\u52a1\u5668\uff0c\u5ba2\u6237\u7aef\u80fd\u8ba4\u8bc6\u54ea\u4e9b\u683c\u5f0f,\u6700\u597d\u8fd4\u56de\u8fd9\u4e9b\u683c\u5f0f<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">consumes \u7528\u6765\u9650\u5236ContentType\nproduces \u7528\u6765\u9650\u5236Accept<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">value\uff0c method\uff1b\nvalue\uff1a   \u6307\u5b9a\u8bf7\u6c42\u7684\u5b9e\u9645\u5730\u5740\uff0c\u6307\u5b9a\u7684\u5730\u5740\u53ef\u4ee5\u662fURI Template \u6a21\u5f0f\uff08\u540e\u9762\u5c06\u4f1a\u8bf4\u660e\uff09\uff1b\nmethod\uff1a  \u6307\u5b9a\u8bf7\u6c42\u7684method\u7c7b\u578b\uff0c PUT\u3001GET\u3001DELETE\u3001POST \u5206\u522b\u5bf9\u5e94\u6ce8\u89e3@PutMapping @GetMapping @DeleteMapping @PostMapping\uff1b\n\nconsumes\uff0cproduces\uff1b\nconsumes\uff1a \u6307\u5b9a\u5904\u7406\u8bf7\u6c42\u7684\u63d0\u4ea4\u5185\u5bb9\u7c7b\u578b\uff08Content-Type\uff09\uff0c\u4f8b\u5982application\/json, text\/html;\nproduces:    \u6307\u5b9a\u8fd4\u56de\u7684\u5185\u5bb9\u7c7b\u578b\uff0c\u4ec5\u5f53request\u8bf7\u6c42\u5934\u4e2d\u7684(Accept)\u7c7b\u578b\u4e2d\u5305\u542b\u8be5\u6307\u5b9a\u7c7b\u578b\u624d\u8fd4\u56de\uff1b\n\nparams\uff0cheaders\uff1b\nparams\uff1a \u6307\u5b9arequest\u4e2d\u5fc5\u987b\u5305\u542b\u67d0\u4e9b\u53c2\u6570\u503c\u662f\uff0c\u624d\u8ba9\u8be5\u65b9\u6cd5\u5904\u7406\u3002\nheaders\uff1a \u6307\u5b9arequest\u4e2d\u5fc5\u987b\u5305\u542b\u67d0\u4e9b\u6307\u5b9a\u7684header\u503c\uff0c\u624d\u80fd\u8ba9\u8be5\u65b9\u6cd5\u5904\u7406\u8bf7\u6c42\u3002\n\n\/**\n* consumes \u6807\u8bc6\u5904\u7406request Content-Type\u4e3a\u201capplication\/json\u201d\u7c7b\u578b\u7684\u8bf7\u6c42.\n* produces\u6807\u8bc6\u5904\u7406request\u8bf7\u6c42\u4e2dAccept\u5934\u4e2d\u5305\u542b\u4e86\"application\/json\"\u7684\u8bf7\u6c42.\n* \u540c\u65f6\u6697\u793a\u4e86\u8fd4\u56de\u7684\u5185\u5bb9\u7c7b\u578b\u4e3aapplication\/json;\n*\/\n  @ApiOperation(value = \"\u4fdd\u5b58\u7528\u6237\")\n  @PostMapping(value = \"\/execute\",produces = MediaType.APPLICATION_JSON_VALUE,consumes = MediaType.APPLICATION_JSON_VALUE)\n  public String saveUser(@RequestBody User userl){\n        \/\/TO DO\n        return \"\u4fdd\u5b58\u6210\u529f\";\n  }\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb \u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\uff0c\u7ecf\u5e38\u5173\u6ce8\u6838\u5fc3\u7684\u4e1a\u52a1\u6216\u8005\u6838\u5fc3\u7684\u67b6\u6784\u624b\u6cd5\uff0c\u5f80\u5f80\u5ffd\u7565\u4e86\u4e00\u4e9b\u5c0f\u7684\u70b9\u70b9\u6ef4\u6ef4\u4eca\u5929\u5c31\u8bb0\u5f55\u4e0b\u5728Spring [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8582"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8582"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8582\/revisions"}],"predecessor-version":[{"id":8583,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8582\/revisions\/8583"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}