{"id":3131,"date":"2018-09-28T16:10:38","date_gmt":"2018-09-28T08:10:38","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3131"},"modified":"2018-09-28T16:10:38","modified_gmt":"2018-09-28T08:10:38","slug":"spring-boot-webflux-bootstrap-%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3131","title":{"rendered":"Spring Boot WebFlux Bootstrap \u6587\u4ef6\u4e0a\u4f20"},"content":{"rendered":"<p>\n\t\u5728\u524d\u9762\u4e24\u7bc7\u57fa\u7840\u6587\u7ae0\u7684\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u4eca\u5929\u5728\u5b66\u4e60\u7b2c\u4e09\u7ae0\uff0cWebFlux \u7684\u6587\u4ef6\u4e0a\u4f20\u3002\u4e3a\u4e86\u6f14\u793a\u6548\u679c\uff0c\u6211\u8fd9\u91cc\u524d\u7aef\u501f\u7528\u4e86 Bootstrap \u6846\u67b6\u3002\u800c\u4e14\u662f\u652f\u6301\u591a\u8bed\u8a00\uff0c\u591a\u6587\u4ef6\uff0c\u6709\u8fdb\u5ea6\u6761\u7684\u4e0a\u4f20\uff0c\u540c\u65f6\u5728\u4e0a\u4f20\u4e4b\u524d\u8fd8\u53ef\u4ee5\u9884\u89c8\u56fe\u7247\u3002\u524d\u7aef\u7684\u4ee3\u7801\u505a\u6cd5\u53c2\u8003\u6211\u7684\u8fd9\u7bc7\u6587\u7ae0\uff1a<a href=\"https:\/\/www.xttblog.com\/?p=1150\">\u4f7f\u7528Bootstrap\u7684fileinput\u63d2\u4ef6\u5b9e\u73b0\u591a\u6587\u4ef6\u3001\u591a\u8bed\u8a00\u3001\u53ef\u9884\u89c8\u7684\u4e0a\u4f20\u529f\u80fd<\/a>\u3002\n<\/p>\n<p>\n\t\u5728\u524d\u9762\u4e24\u7bc7\u7684\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u65b0\u5efa&nbsp;webflux-file \u5de5\u7a0b\u3002maven \u7684 pom.xml \u548c\u524d\u9762\u4e00\u6837\uff0c\u542f\u52a8\u7c7b\u4e5f\u4e00\u6837\u3002\u8be6\u60c5\u53ef\u4ee5\u53c2\u8003\u524d\u9762\u7684\u4e24\u7bc7\u6587\u7ae0\u6216\u8005\u626b\u63cf\u6587\u7ae0\u672b\u5c3e\u7684\u4e8c\u7ef4\u7801\uff0c\u5173\u6ce8&ldquo;\u4e1a\u4f59\u8349&rdquo;\u5fae\u4fe1\u516c\u4f17\u53f7\u8fdb\u884c\u4e0b\u8f7d\uff01\n<\/p>\n<p>\n\t\u73b0\u5728\u6211\u4eec\u65b0\u5efa\u4e00\u4e2a&nbsp;FileRouter \u7c7b\uff0c\u6216\u8005&nbsp;FileController \u7c7b\u4e5f\u53ef\u4ee5\uff0c\u540e\u9762\u6211\u4f1a\u8bf4\u4ed6\u4eec\u4e4b\u95f4\u7684\u533a\u522b\u3002\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\n@RestController\r\npublic class FileRouter {\r\n\r\n    @PostMapping(value = &quot;\/upload&quot;, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)\r\n    public Mono&lt;String&gt; requestBodyFlux(@RequestPart(&quot;file&quot;) FilePart filePart) throws IOException {\r\n\r\n        System.out.println(filePart.filename());\r\n        Path tempFile = Files.createTempFile(&quot;xttblog&quot;, filePart.filename());\r\n\r\n        \/\/NOTE \u65b9\u6cd5\u4e00\r\n        AsynchronousFileChannel channel =\r\n                AsynchronousFileChannel.open(tempFile, StandardOpenOption.WRITE);\r\n        DataBufferUtils.write(filePart.content(), channel, 0)\r\n                .doOnComplete(() -&gt; {\r\n                    System.out.println(&quot;finish&quot;);\r\n                })\r\n                .subscribe();\r\n\r\n        \/\/NOTE \u65b9\u6cd5\u4e8c\r\n        \/\/filePart.transferTo(tempFile.toFile());\r\n\r\n        System.out.println(tempFile.toString());\r\n        return Mono.just(filePart.filename());\r\n    }\r\n\r\n    @GetMapping(&quot;\/download&quot;)\r\n    public Mono&lt;Void&gt; downloadByWriteWith(ServerHttpResponse response) throws IOException {\r\n        ZeroCopyHttpOutputMessage zeroCopyResponse = (ZeroCopyHttpOutputMessage) response;\r\n        response.getHeaders().set(HttpHeaders.CONTENT_DISPOSITION, &quot;attachment; filename=xttblog.png&quot;);\r\n        response.getHeaders().setContentType(MediaType.IMAGE_PNG);\r\n\r\n        Resource resource = new ClassPathResource(&quot;xttblog.png&quot;);\r\n        File file = resource.getFile();\r\n        return zeroCopyResponse.writeWith(file, 0, file.length());\r\n    }\r\n}<\/pre>\n<p>\n\t\u6838\u5fc3\u4ee3\u7801\u5c31\u8fd9\u4e48\u591a\uff0c\u4e0a\u4f20\u4e0b\u8f7d\u5168\u5728\u8fd9\u91cc\u3002\u4e0a\u4f20\u6211\u4eec\u4e3b\u8981\u662f\u4f7f\u7528\u4e86&nbsp;FilePart \u7c7b\u548c @RequestPart(&quot;file&quot;) \u6ce8\u89e3\u3002\u4e0b\u8f7d\u4f7f\u7528\u7684\u662f webflux \u63d0\u4f9b\u7684&nbsp;ServerHttpResponse \u7c7b\uff0c\u76f4\u63a5\u5c06\u6587\u4ef6\u5199\u5165\u5230\u8f93\u51fa\u6d41\u3002\n<\/p>\n<h2>\n\tfileinput.js \u5b9e\u73b0\u6587\u4ef6\u4e0a\u4f20\u7684\u8fd0\u884c\u6548\u679c<br \/>\n<\/h2>\n<p>\n\t<img decoding=\"async\" alt=\"Bootstrap fileinput.js \u00e5\u00ae\u009e\u00e7\u008e\u00b0\u00e5\u00a4\u009a\u00e6\u0096\u0087\u00e4\u00bb\u00b6\u00e4\u00b8\u008a\u00e4\u00bc\u00a0\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/bootstrap-file1.png\" \/>\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Bootstrap fileinput.js \u00e5\u00ae\u009e\u00e7\u008e\u00b0\u00e6\u0096\u0087\u00e4\u00bb\u00b6\u00e9\u00a2\u0084\u00e8\u00a7\u0088\u00e5\u008a\u009f\u00e8\u0083\u00bd\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/bootstrap-file2.png\" \/>\n<\/p>\n<p>\n\t\u6587\u4ef6\u4e0a\u4f20\u540e\uff0c\u63a7\u5236\u53f0\u6253\u5370\u4fe1\u606f\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:plain;\">\r\nxttblog.png\r\n\/var\/folders\/rc\/z5hy_bp96_z43zy6mb7hqg4w0000gn\/T\/xttblog6929117607868758568xttblog.png\r\nfinish<\/pre>\n<p>\n\t\u6211\u8fd9\u91cc\u662f mac \u7535\u8111\uff0c\u6253\u5370\u5185\u5bb9\u548c Linux \u4e0a\u4e00\u81f4\u3002\u6700\u540e\u5173\u4e8e\u6e90\u7801\uff0c\u626b\u63cf\u4e0b\u65b9\u4e8c\u7ef4\u7801\uff0c\u5173\u6ce8&ldquo;\u4e1a\u4f59\u8349&rdquo;\u5fae\u4fe1\u516c\u4f17\u53f7\uff0c\u56de\u590d\uff1a&ldquo;webflux&rdquo;\u5173\u952e\u5b57\u5373\u53ef\u514d\u8d39\u4e0b\u8f7d\uff01<\/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=3131\">Spring Boot WebFlux Bootstrap \u6587\u4ef6\u4e0a\u4f20<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5728\u524d\u9762\u4e24\u7bc7\u57fa\u7840\u6587\u7ae0\u7684\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u4eca\u5929\u5728\u5b66\u4e60\u7b2c\u4e09\u7ae0\uff0cWebFlux \u7684\u6587\u4ef6\u4e0a\u4f20\u3002\u4e3a\u4e86\u6f14\u793a\u6548\u679c\uff0c\u6211\u8fd9\u91cc\u524d\u7aef\u501f\u7528\u4e86  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[627,1522,1638,413,1701],"class_list":["post-3131","post","type-post","status-publish","format-standard","hentry","category-java","tag-bootstrap","tag-springboot","tag-springcloud","tag-springmvc","tag-webflux"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3131","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=3131"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3131\/revisions"}],"predecessor-version":[{"id":3132,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3131\/revisions\/3132"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}