{"id":3678,"date":"2019-01-04T17:44:36","date_gmt":"2019-01-04T09:44:36","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3678"},"modified":"2019-01-04T17:44:36","modified_gmt":"2019-01-04T09:44:36","slug":"webflux-%e6%95%b4%e5%90%88-thymeleaf-%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3678","title":{"rendered":"WebFlux \u6574\u5408 thymeleaf \u6559\u7a0b"},"content":{"rendered":"<p>\n\tWebFlux \u662f\u4e00\u79cd\u8d8b\u52bf\uff0c\u4f5c\u4e3a\u7a0b\u5e8f\u5458\u6211\u4eec\u4e5f\u5e94\u8be5\u770b\u5230\u672a\u6765\u7684\u8d8b\u52bf\uff0c\u672a\u6765\u7684\u70ed\u95e8\u6280\u672f\u3002\u6211\u4e2a\u4eba\u611f\u89c9&nbsp;WebFlux \u672a\u6765\u4f1a\u53d6\u4ee3 Spring MVC\uff0c\u56e0\u6b64\u6211\u82b1\u4e86\u5f88\u591a\u7684\u65f6\u95f4\u548c\u7cbe\u529b\u5728\u5b66\u4e60&nbsp;WebFlux\u3002\u672c\u6587\u6211\u4eec\u4e00\u8d77\u6765\u5b66\u4e60&nbsp;WebFlux \u6574\u5408&nbsp;thymeleaf \u5427\uff01\n<\/p>\n<p>\n\t\u5148\u770b\u4e00\u4e0b\uff0c\u6211\u4eec\u7684\u8fd0\u884c\u6548\u679c\u5427\uff01\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"WebFlux \u6574\u5408 thymeleaf \u6559\u7a0b\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fyuoye154mj227y12e0z0.jpg\" style=\"width: 2878px;height: 1382px\" \/>\n<\/p>\n<p>\n\t\u4e0b\u9762\u6211\u4eec\u5f00\u59cb\u4ee3\u7801\u7684\u7f16\u5199\u3002\n<\/p>\n<p>\n\tWebFlux \u6574\u5408 thymeleaf \u4e5f\u975e\u5e38\u7684\u7b80\u5355\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5728 spring-boot-starter-webflux \u7684\u57fa\u7840\u4e0a\uff0c\u518d\u5f15\u5165 spring-boot-starter-thymeleaf \u5373\u53ef\u3002\u76f8\u5173\u7684 pom.xml \u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\n&lt;properties&gt;\r\n    &lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;\r\n    &lt;project.reporting.outputEncoding&gt;UTF-8&lt;\/project.reporting.outputEncoding&gt;\r\n    &lt;java.version&gt;1.8&lt;\/java.version&gt;\r\n&lt;\/properties&gt;\r\n&lt;dependencies&gt;\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;spring-boot-starter-webflux&lt;\/artifactId&gt;\r\n    &lt;\/dependency&gt;\r\n    &lt;!-- thymeleaf \u6a21\u7248\u5f15\u64ce --&gt;\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;\/artifactId&gt;\r\n    &lt;\/dependency&gt;\r\n    &lt;!-- \u70ed\u90e8\u7f72 --&gt;\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;spring-boot-devtools&lt;\/artifactId&gt;\r\n        &lt;scope&gt;runtime&lt;\/scope&gt;\r\n    &lt;\/dependency&gt;\r\n&lt;\/dependencies&gt;\r\n&lt;build&gt;\r\n    &lt;plugins&gt;\r\n        &lt;plugin&gt;\r\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt;\r\n        &lt;\/plugin&gt;\r\n    &lt;\/plugins&gt;\r\n&lt;\/build&gt;<\/pre>\n<p>\n\t\u7136\u540e\u6211\u4eec\u5728\u9879\u76ee\u7684 src\/main\/resources\/templates\/ \u4e0b\u65b0\u5efa\u4e00\u4e2a\u6d4b\u8bd5\u7684\u6a21\u677f\u9875\u9762 xttblog.html\u3002xttblog.html \u9875\u9762\u5185\u5bb9\u4f60\u53ef\u4ee5\u81ea\u884c\u89c4\u5212\u3002\n<\/p>\n<p>\n\t\u7136\u540e\uff0c\u6211\u4eec\u5728 src\/main\/resources\/ \u76ee\u5f55\u4e0b\uff0c\u65b0\u5efa application.yml \u914d\u7f6e\u6587\u4ef6\u3002\u5185\u5bb9\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\nspring:\r\n  thymeleaf:\r\n    prefix: classpath:\/templates\/\r\n    enabled: true\r\n    suffix: .html\r\n    cache: false\r\n    template-resolver-order: 1\r\n    check-template: false\r\n    reactive:\r\n      max-chunk-size: 8192<\/pre>\n<p>\n\t\u6700\u540e\u662f Java \u4ee3\u7801\uff0c\u4e3a\u4e86\u65b9\u4fbf\u6211\u5c31\u8d34\u5230\u4e00\u8d77\u4e86\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\n@Configuration\r\npublic class OAuthWeixinRouter {\r\n    @Autowired\r\n    private WeixinHandler weixinHandler;\r\n    @Bean\r\n    public RouterFunction&lt;ServerResponse&gt; webFluxRoutesRegister(){\r\n        return RouterFunctions\r\n                .route(RequestPredicates.GET(&quot;\/weixin\/login&quot;), weixinHandler::loginPage);\r\n    }\r\n}\r\n@Component\r\npublic class WeixinHandler {\r\n    public Mono&lt;ServerResponse&gt; loginPage(ServerRequest serverRequest) {\r\n        Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();\r\n        map.put(&quot;site&quot;, &quot;www.xttblog.com&quot;);\r\n        map.put(&quot;siteName&quot;, &quot;\u4e1a\u4f59\u8349&quot;);\r\n        \/\/\u8fd4\u56dethymeleaf\u6a21\u7248\u9875\u9762\r\n        return ServerResponse.ok().render(&quot;weixin&quot;, map);\r\n    }\r\n}\r\n@SpringBootApplication\r\npublic class OAuthWeixinApplication {\r\n    public static void main(String[] args) {\r\n        SpringApplication.run(OAuthWeixinApplication.class, args);\r\n    }\r\n}<\/pre>\n<p>\n\tOk\uff0c\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u7684\u4ee3\u7801\u5c31\u5df2\u7ecf\u5199\u5b8c\u4e86\uff0c\u63a5\u4e0b\u6765\u5c31\u542f\u52a8\u9879\u76ee\uff0c\u6d4b\u8bd5\u6d4b\u8bd5\u5427\uff01thymeleaf \u4e2d\u7684\u6240\u6709\u8bed\u6cd5\u548c\u529f\u80fd\u90fd\u53ef\u4ee5\u5728\u4f60\u7684 html \u4e2d\u4f7f\u7528\u3002<\/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=3678\">WebFlux \u6574\u5408 thymeleaf \u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>WebFlux \u662f\u4e00\u79cd\u8d8b\u52bf\uff0c\u4f5c\u4e3a\u7a0b\u5e8f\u5458\u6211\u4eec\u4e5f\u5e94\u8be5\u770b\u5230\u672a\u6765\u7684\u8d8b\u52bf\uff0c\u672a\u6765\u7684\u70ed\u95e8\u6280\u672f\u3002\u6211\u4e2a\u4eba\u611f\u89c9&nbsp;WebF [&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":[1868,1522,1638,1614,1701],"class_list":["post-3678","post","type-post","status-publish","format-standard","hentry","category-java","tag-serverresponse","tag-springboot","tag-springcloud","tag-thymeleaf","tag-webflux"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3678","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=3678"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3678\/revisions"}],"predecessor-version":[{"id":3679,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3678\/revisions\/3679"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}