{"id":36292,"date":"2024-11-26T10:07:26","date_gmt":"2024-11-26T02:07:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36292\/"},"modified":"2024-11-26T10:07:26","modified_gmt":"2024-11-26T02:07:26","slug":"spring-boot-%e5%9b%be%e7%89%87%e9%a2%84%e8%a7%88%e5%92%8c%e4%b8%8b%e8%bd%bd%ef%bc%9asetcontenttype-%e7%9a%84%e4%bd%8d%e7%bd%ae%e5%a6%82%e4%bd%95%e5%86%b3%e5%ae%9a%e8%a1%8c%e4%b8%ba%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36292\/","title":{"rendered":"Spring Boot \u56fe\u7247\u9884\u89c8\u548c\u4e0b\u8f7d\uff1asetContentType \u7684\u4f4d\u7f6e\u5982\u4f55\u51b3\u5b9a\u884c\u4e3a\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173105390492552.jpg\" class=\"aligncenter\" title=\"Spring Boot \u56fe\u7247\u9884\u89c8\u548c\u4e0b\u8f7d\uff1asetContentType \u7684\u4f4d\u7f6e\u5982\u4f55\u51b3\u5b9a\u884c\u4e3a\uff1f\u63d2\u56fe\" alt=\"Spring Boot \u56fe\u7247\u9884\u89c8\u548c\u4e0b\u8f7d\uff1asetContentType \u7684\u4f4d\u7f6e\u5982\u4f55\u51b3\u5b9a\u884c\u4e3a\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>setcontenttype \u5bf9 spring boot \u56fe\u7247\u9884\u89c8\u548c\u4e0b\u8f7d\u7684\u5f71\u54cd<\/strong><\/p>\n<p>\u5728 spring boot 2.5.0 \u4e2d\uff0csetcontenttype \u65b9\u6cd5\u653e\u7f6e\u7684\u4f4d\u7f6e\u4f1a\u5f71\u54cd\u56fe\u7247\u7684\u9884\u89c8\u548c\u4e0b\u8f7d\u3002<\/p>\n<p><strong>\u653e\u5728\u540e\u9884\u89c8<\/strong><\/p>\n<pre>response.setcontenttype(\"image\/*\"); \/\/ \u653e\u5728\u83b7\u53d6\u6587\u4ef6\u6d41\u4e4b\u540e<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0csetcontenttype \u8bbe\u7f6e\u5728\u8bfb\u53d6\u6587\u4ef6\u6d41\u5e76\u8f93\u51fa\u5230 servletoutputstream \u4e4b\u540e\uff0c\u6d4f\u89c8\u5668\u4f1a\u5c06\u54cd\u5e94\u5185\u5bb9\u89c6\u4e3a\u9884\u89c8\u3002\u5373\uff0c\u56fe\u7247\u4f1a\u5728\u6d4f\u89c8\u5668\u4e2d\u663e\u793a\u3002<\/p>\n<p><strong>\u653e\u5728\u524d\u4e0b\u8f7d<\/strong><\/p>\n<pre>response.setContentType(\"image\/*\"); \/\/ \u653e\u5728\u83b7\u53d6\u6587\u4ef6\u6d41\u4e4b\u524d<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5982\u679c\u5c06 setcontenttype \u8bbe\u7f6e\u5728\u8bfb\u53d6\u6587\u4ef6\u6d41\u4e4b\u524d\uff0c\u6d4f\u89c8\u5668\u4f1a\u5c06\u54cd\u5e94\u5185\u5bb9\u89c6\u4e3a\u4e0b\u8f7d\u3002\u5373\uff0c\u6d4f\u89c8\u5668\u4f1a\u5f39\u51fa\u6587\u4ef6\u4e0b\u8f7d\u5bf9\u8bdd\u6846\uff0c\u8ba9\u7528\u6237\u4fdd\u5b58\u6587\u4ef6\u3002<\/p>\n<p><strong>\u8bf4\u660e<\/strong><\/p>\n<p>\u5f53\u6d4f\u89c8\u5668\u6536\u5230\u54cd\u5e94\u65f6\uff0c\u5b83\u4f1a\u6839\u636e\u54cd\u5e94\u5185\u5bb9\u7c7b\u578b\u51b3\u5b9a\u5982\u4f55\u5904\u7406\u54cd\u5e94\u5185\u5bb9\u3002\u5982\u679c\u5185\u5bb9\u7c7b\u578b\u8bbe\u7f6e\u4e3a\u56fe\u50cf\uff0c\u5219\u6d4f\u89c8\u5668\u4f1a\u9884\u89c8\u54cd\u5e94\u5185\u5bb9\uff1b\u5982\u679c\u5185\u5bb9\u7c7b\u578b\u8bbe\u7f6e\u4e3a\u4e0b\u8f7d\u6587\u4ef6\uff0c\u5219\u6d4f\u89c8\u5668\u4f1a\u5f39\u51fa\u6587\u4ef6\u4e0b\u8f7d\u5bf9\u8bdd\u6846\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u5982\u679c\u9700\u8981\u9884\u89c8\u56fe\u7247\uff0c\u8bf7\u5c06 setcontenttype \u653e\u5728\u83b7\u53d6\u6587\u4ef6\u6d41\u4e4b\u540e\uff0c\u5426\u5219\u5c06\u5f39\u51fa\u6587\u4ef6\u4e0b\u8f7d\u5bf9\u8bdd\u6846\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fSpring Boot \u56fe\u7247\u9884\u89c8\u548c\u4e0b\u8f7d\uff1asetContentType \u7684\u4f4d\u7f6e\u5982\u4f55\u51b3\u5b9a\u884c\u4e3a\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>setcontenttype \u5bf9 spring boot \u56fe\u7247\u9884\u89c8\u548c\u4e0b\u8f7d\u7684\u5f71\u54cd \u5728 spring boot 2.5.0 \u4e2d\uff0csetcontenttype \u65b9\u6cd5\u653e\u7f6e\u7684\u4f4d\u7f6e\u4f1a\u5f71\u54cd\u56fe\u7247\u7684\u9884\u89c8\u548c\u4e0b\u8f7d\u3002 \u653e\u5728\u540e\u9884\u89c8 response.setcontenttype(&#8220;image\/*&#8221;); \/\/ \u653e\u5728\u83b7\u53d6\u6587\u4ef6\u6d41\u4e4b\u540e \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0csetcontenttype \u8bbe\u7f6e\u5728\u8bfb\u53d6\u6587\u4ef6\u6d41\u5e76\u8f93\u51fa\u5230 servletoutputstream \u4e4b\u540e\uff0c\u6d4f\u89c8\u5668\u4f1a\u5c06\u54cd\u5e94\u5185\u5bb9\u89c6\u4e3a\u9884\u89c8\u3002\u5373\uff0c\u56fe\u7247\u4f1a\u5728\u6d4f\u89c8\u5668\u4e2d\u663e\u793a\u3002 \u653e\u5728\u524d\u4e0b\u8f7d response.setContentType(&#8220;image\/*&#8221;); \/\/ \u653e\u5728\u83b7\u53d6\u6587\u4ef6\u6d41\u4e4b\u524d \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u5c06 setcontenttype \u8bbe\u7f6e\u5728\u8bfb\u53d6\u6587\u4ef6\u6d41\u4e4b\u524d\uff0c\u6d4f\u89c8\u5668\u4f1a\u5c06\u54cd\u5e94\u5185\u5bb9\u89c6\u4e3a\u4e0b\u8f7d\u3002\u5373\uff0c\u6d4f\u89c8\u5668\u4f1a\u5f39\u51fa\u6587\u4ef6\u4e0b\u8f7d\u5bf9\u8bdd\u6846\uff0c\u8ba9\u7528\u6237\u4fdd\u5b58\u6587\u4ef6\u3002 \u8bf4\u660e \u5f53\u6d4f\u89c8\u5668\u6536\u5230\u54cd\u5e94\u65f6\uff0c\u5b83\u4f1a\u6839\u636e\u54cd\u5e94\u5185\u5bb9\u7c7b\u578b\u51b3\u5b9a\u5982\u4f55\u5904\u7406\u54cd\u5e94\u5185\u5bb9\u3002\u5982\u679c\u5185\u5bb9\u7c7b\u578b\u8bbe\u7f6e\u4e3a\u56fe\u50cf\uff0c\u5219\u6d4f\u89c8\u5668\u4f1a\u9884\u89c8\u54cd\u5e94\u5185\u5bb9\uff1b\u5982\u679c\u5185\u5bb9\u7c7b\u578b\u8bbe\u7f6e\u4e3a\u4e0b\u8f7d\u6587\u4ef6\uff0c\u5219\u6d4f\u89c8\u5668\u4f1a\u5f39\u51fa\u6587\u4ef6\u4e0b\u8f7d\u5bf9\u8bdd\u6846\u3002 \u6240\u4ee5\uff0c\u5982\u679c\u9700\u8981\u9884\u89c8\u56fe\u7247\uff0c\u8bf7\u5c06 setcontenttype \u653e\u5728\u83b7\u53d6\u6587\u4ef6\u6d41\u4e4b\u540e\uff0c\u5426\u5219\u5c06\u5f39\u51fa\u6587\u4ef6\u4e0b\u8f7d\u5bf9\u8bdd\u6846\u3002 \u4ee5\u4e0a\u5c31\u662fSpring Boot \u56fe\u7247\u9884\u89c8\u548c\u4e0b\u8f7d\uff1asetContentType \u7684\u4f4d\u7f6e\u5982\u4f55\u51b3\u5b9a\u884c\u4e3a\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-36292","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=36292"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36292\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}