{"id":3929,"date":"2019-02-26T18:33:16","date_gmt":"2019-02-26T10:33:16","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3929"},"modified":"2020-02-08T14:26:35","modified_gmt":"2020-02-08T06:26:35","slug":"webflux-%e9%9d%99%e6%80%81%e8%b5%84%e6%ba%90%e5%a4%84%e7%90%86%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3929","title":{"rendered":"WebFlux \u9759\u6001\u8d44\u6e90\u5904\u7406\u6559\u7a0b"},"content":{"rendered":"<p>\u5173\u4e8e WebFlux \u7684\u6559\u7a0b\u65b9\u9762\u7684\u5185\u5bb9\u6211\u5df2\u7ecf\u6301\u7eed\u5199\u8fc7\u5f88\u591a\u5185\u5bb9\u4e86\u3002\u5305\u62ec\u524d\u9762\u7684\u8fd9\u7bc7\u300a<a href=\"https:\/\/www.xttblog.com\/?p=3678\">WebFlux \u6574\u5408 thymeleaf \u6559\u7a0b<\/a>\u300b\u6587\u7ae0\uff0c\u5bf9\u9759\u6001\u8d44\u6e90\u7684\u5904\u7406\uff0c\u63d0\u5230\u7684\u90fd\u975e\u5e38\u7684\u5c11\u3002\u4eca\u5929\u6211\u62bd\u4e2a\u65f6\u95f4\u4e13\u95e8\u628a&nbsp;WebFlux \u5bf9\u9759\u6001\u8d44\u6e90\u7684\u6620\u5c04\u6765\u5199\u4e00\u5199\uff01<\/p>\n<p>\u6240\u8c13\u7684\u9759\u6001\u8d44\u6e90\uff0c\u4e3b\u8981\u5c31\u662f\u6307 css\u3001js\u3001\u56fe\u7247\u7b49\u8fd9\u7c7b\u6587\u4ef6\u3002\u6211\u4e0d\u9700\u8981\u6bcf\u4e2a\u90fd\u7ed9\u4f60\u914d\u7f6e\u4e00\u4e2a\u8def\u7531\uff0c\u76f4\u63a5\u7ed9\u4f60\u4e00\u4e2a\u89c4\u5219\uff0csrc\/main\/resources\/public \u76ee\u5f55\u4e0b\u7684\u5168\u662f\u9759\u6001\u6587\u4ef6\uff0c\u8bbf\u95ee\u8fd9\u4e2a\u76ee\u5f55\u7684\u5185\u5bb9\uff0c\u76f4\u63a5\u6620\u5c04\u4e00\u4e0b\u3002<\/p>\n<p>\u8fd9\u4e2a\u60f3\u6cd5\u5f88\u597d\uff0cWebFlux \u4e2d\u4e5f\u63d0\u4f9b\u4e86\u7c7b\u4f3c\u7684\u529f\u80fd\u3002\u9ed8\u8ba4\u5c31\u4f1a\u8fdb\u884c\u9759\u6001\u8d44\u6e90\u6620\u5c04\u3002\u524d\u63d0\u662f\u4f60\u7684\u9759\u6001\u8d44\u6e90\u5fc5\u987b\u653e\u5728&nbsp;src\/main\/resources\/public \u76ee\u5f55\u4e0b\u3002<\/p>\n<p><img decoding=\"async\" style=\"width: 290px;height: 304px\" src=\"https:\/\/gitee.com\/xmtblog\/img\/raw\/master\/8fa5dcfcgy1g0k06a8l7uj208208gt95.jpg\" alt=\"WebFlux \u5904\u7406\u9759\u6001\u8d44\u6e90\"><\/p>\n<p>\u5982\u679c\u4f60\u65b0\u5efa\u4e86\u4e00\u4e2a\u76ee\u5f55\uff0c\u6bd4\u5982\uff0csrc\/main\/resources\/static\u3002\u90a3\u5bf9\u4e0d\u8d77\uff0cWebFlux \u5c06\u65e0\u6cd5\u8fdb\u884c\u81ea\u52a8\u6620\u5c04\u3002<\/p>\n<p>\u8fd9\u4e2a\u65f6\u5019\uff0c\u6211\u4eec\u5c31\u6709\u4e24\u79cd\u505a\u6cd5\u6765\u8fdb\u884c\u6539\u53d8\u6620\u5c04\u7684\u8def\u5f84\u3002<\/p>\n<p>\u7b2c\u4e00\u79cd\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u7684\u5f62\u5f0f\uff0c\u6307\u5b9a spring.resources.static-locations \u548c spring.webflux.static-path-pattern \u4e24\u4e2a\u5c5e\u6027\u503c\u5373\u53ef\u3002\u8fd9\u4e2a\u914d\u7f6e\u975e\u5e38\u7b80\u5355\uff0c\u770b\u5c5e\u6027\u540d\u79f0\u5c31\u77e5\u9053\u5982\u4f55\u914d\u7f6e\u4e86\u3002\u6211\u5c31\u4e0d\u7ec6\u8bf4\u4e86\uff0c\u6211\u91cd\u70b9\u8bf4\u4e00\u4e0b\u7b2c\u4e8c\u79cd\u65b9\u6848\u3002<\/p>\n<p>\u7b2c\u4e8c\u79cd\u529e\u6cd5\u5c31\u662f\uff0c\u901a\u8fc7 RouterFunctions.resources \u6765\u6307\u5b9a\u548c\u6620\u5c04\u9759\u6001\u8d44\u6e90\u3002<\/p>\n<p><img decoding=\"async\" style=\"width: 301px;height: 401px\" src=\"https:\/\/gitee.com\/xmtblog\/img\/raw\/master\/8fa5dcfcgy1g0k07s5y9tj208d0b5gma.jpg\" alt=\"RouterFunctions.resources\"><\/p>\n<p>\u73b0\u5728\u5047\u8bbe\uff0c\u6211\u4eec\u7684\u9759\u6001\u8d44\u6e90\u653e\u7f6e\u5728 src\/main\/resources\/statica \u76ee\u5f55\u4e0b\u3002\u8fd9\u662f\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u76ee\u5f55 statica\uff0c\u6211\u4e13\u95e8\u52a0\u4e86\u4e00\u4e2a a\uff0c\u4e0d\u662f\u5199\u9519\u4e86\uff0c\u6545\u610f\u7684\u3002<\/p>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u901a\u8fc7 RouterFunctions.resources \u5c31\u53ef\u4ee5\u8fd9\u6837\u6765\u505a\u3002<\/p>\n<pre class=\"brush:java;\">@Configuration\npublic class StaticRoute {\n    @Bean\n    RouterFunction&lt;ServerResponse&gt; staticResourceRouter(){\n        return RouterFunctions.resources(\"\/statica\/**\", \n                new ClassPathResource(\"statica\/\"));\n    }\n}<\/pre>\n<p>\u8fd9\u6837\uff0c\u91cd\u542f\u9879\u76ee\u5c31\u53ef\u4ee5\u4f7f\u7528\u6307\u5b9a\u7684\u76ee\u5f55\u5b58\u653e\u9759\u6001\u8d44\u6e90\u4e86\u3002<\/p>\n<p>\u4ee5\u4e0a\uff0c\u5982\u679c\u4f60\u8fd8\u6709\u7591\u95ee\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7\uff0c\u548c\u6211\u4e00\u8d77\u63a2\u8ba8 WebFlux \u7684\u5965\u79d8\u3002<\/p>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3929\">WebFlux \u9759\u6001\u8d44\u6e90\u5904\u7406\u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e WebFlux \u7684\u6559\u7a0b\u65b9\u9762\u7684\u5185\u5bb9\u6211\u5df2\u7ecf\u6301\u7eed\u5199\u8fc7\u5f88\u591a\u5185\u5bb9\u4e86\u3002\u5305\u62ec\u524d\u9762\u7684\u8fd9\u7bc7\u300aWebFlux \u6574\u5408 thym [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1710,1709,1937,1868,1701],"class_list":["post-3929","post","type-post","status-publish","format-standard","hentry","category-java","tag-flux","tag-mono","tag-routerfunctions","tag-serverresponse","tag-webflux"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3929","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3929"}],"version-history":[{"count":3,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3929\/revisions"}],"predecessor-version":[{"id":4754,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3929\/revisions\/4754"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}