{"id":4856,"date":"2022-01-06T15:02:23","date_gmt":"2022-01-06T07:02:23","guid":{"rendered":"http:\/\/123.57.164.21\/?p=4856"},"modified":"2022-01-06T15:02:23","modified_gmt":"2022-01-06T07:02:23","slug":"springboot%e4%b8%ad-%e8%af%bb%e5%8f%96%e9%a1%b9%e7%9b%ae%e4%b8%ad%e8%b5%84%e6%ba%90%e6%96%87%e4%bb%b6%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=4856","title":{"rendered":"SpringBoot\u4e2d \u8bfb\u53d6\u9879\u76ee\u4e2d\u8d44\u6e90\u6587\u4ef6\u7684\u95ee\u9898"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">\u524d\u8a00<\/h5>\n\n\n\n<p>SpringBoot<a rel=\"noreferrer noopener\" href=\"https:\/\/so.csdn.net\/so\/search?q=%E5%BE%AE%E6%9C%8D%E5%8A%A1\" target=\"_blank\">\u5fae\u670d\u52a1<\/a>\u5df2\u6210\u4e3a\u4e1a\u754c\u4e3b\u6d41\uff0c\u4ece\u5f00\u53d1\u5230\u90e8\u7f72\u90fd\u975e\u5e38\u7701\u65f6\u7701\u529b\uff0c\u4f46\u662f\u6700\u8fd1\u5c0f\u660e\u5f00\u53d1\u65f6\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff1a\u5728\u4ee3\u7801\u4e2d\u8bfb\u53d6\u8d44\u6e90\u6587\u4ef6(\u6bd4\u5982word\u6587\u6863\u3001\u5bfc\u51fa\u6a21\u7248\u7b49)\uff0c\u672c\u5730\u5f00\u53d1\u65f6\u53ef\u4ee5\u6b63\u5e38\u8bfb\u53d6 \uff0c\u4f46\u662f\uff0c\u5f53\u6211\u4eec\u6253\u6210jar\u5305\u53d1\u5e03\u5230\u670d\u52a1\u5668\u540e\uff0c\u518d\u6b21\u6267\u884c\u7a0b\u5e8f\u65f6\u5c31\u4f1a\u629b\u51fa\u627e\u4e0d\u5230\u6587\u4ef6\u7684\u5f02\u5e38\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u95ee\u9898<\/h5>\n\n\n\n<p>\u8fd9\u4e2adocx\u6587\u6863\u6240\u5728\u76ee\u5f55\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-13-1024x529.png\" alt=\"\" class=\"wp-image-4858\" width=\"580\" height=\"299\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-13-1024x529.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-13-300x155.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-13-768x397.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-13-830x429.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-13-230x119.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-13-350x181.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-13-480x248.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-13.png 1486w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/figure><\/div>\n\n\n\n<p>\u5728\u672c\u5730\u8c03\u8bd5\u65f6\uff0c\u6211\u4f7f\u7528\u5982\u4e0b\u65b9\u5f0f\u8bfb\u53d6\uff1a<\/p>\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=\"\">import org.springframework.util.ResourceUtils;\n    public static void main(String[] args) throws IOException {\n       File docxTemplate = ResourceUtils.getFile(\"classpath:templates\/docxTemplate.docx\");\n    }<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u6b63\u5e38\u89e3\u6790\u4f7f\u7528\uff0c\u4f46\u662f\u6253\u5305\u53d1\u5e03\u5230beta\u73af\u5883\u5374\u4e0d\u53ef\u7528\u3002\u629b\u51fa\u5f02\u5e38\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>java.io.FileNotFoundException: class path resource [templates\/docxTemplate.docx] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:\/usr\/local\/subject-server.jar!\/BOOT-INF\/classes!\/templates\/docxTemplate.docx<br><\/p><\/blockquote>\n\n\n\n<p>\u663e\u800c\u6613\u89c1\uff0c\u8fd9\u4e2a\u5f02\u5e38\u544a\u8bc9\u6211\u4eec\uff1a\u6ca1\u6709\u627e\u5230\u6587\u4ef6\uff0c\u4f46\u662f\u5c06jar\u5305\u89e3\u538b\u8fc7\u540e\uff0c\u53d1\u73b0\u8fd9\u4e2a\u6587\u4ef6\u662f\u771f\u771f\u5b9e\u5b9e\u5b58\u5728\u7684\u3002\u90a3\u8fd9\u5230\u5e95\u662f\u600e\u4e48\u56de\u4e8b\u5462\uff1f\u8fd9\u538b\u6839\u96be\u4e0d\u5012\u6211\u3002\u6211\u4eec\u8981\u5584\u4e8e\u900f\u8fc7\u5806\u6808\u4fe1\u606f\u770b\u672c\u8d28\u3002\u901a\u8fc7\u4ed4\u7ec6\u89c2\u5bdf\u5806\u6808\u4fe1\u606f\uff0c\u6211\u53d1\u73b0\u6b64\u65f6\u7684\u6587\u4ef6\u8def\u5f84\u5e76\u4e0d\u662f\u4e00\u4e2a\u5408\u6cd5\u7684URL(\u6587\u4ef6\u8d44\u6e90\u5b9a\u4f4d\u7b26)\u3002\u539f\u6765jar\u5305\u4e2d\u8d44\u6e90\u6709\u5176\u4e13\u95e8\u7684URL\u5f62\u5f0f\uff1ajar:!\/{entry} )\u3002\u6240\u4ee5\uff0c\u6b64\u65f6\u5982\u679c\u4ecd\u7136\u6309\u7167\u6807\u51c6\u7684\u6587\u4ef6\u8d44\u6e90\u5b9a\u4f4d\u5f62\u5f0f<\/p>\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=\"\">File\u00a0f=new\u00a0File(\"jar:file:\u2026\u2026\");<\/pre>\n\n\n\n<p>\u5b9a\u4f4d\u6587\u4ef6\uff0c\u5c31\u4f1a\u629b\u51fa<strong>java.io.FileNotFoundException<\/strong>\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u89e3\u51b3<\/h5>\n\n\n\n<p>\u867d\u7136\u6211\u4eec\u4e0d\u80fd\u7528\u5e38\u89c4\u64cd\u4f5c\u6587\u4ef6\u7684\u65b9\u6cd5\u6765\u8bfb\u53d6jar\u5305\u4e2d\u7684\u8d44\u6e90\u6587\u4ef6<strong>docxTemplate.docx<\/strong>\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7<strong>Class<\/strong>\u7c7b\u7684<strong>getResourceAsStream<\/strong>()\u65b9\u6cd5\uff0c\u5373\u901a\u8fc7\u6d41\u7684\u65b9\u5f0f\u6765\u83b7\u53d6 \uff1a<\/p>\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=\"\">public static void main(String[] args) throws IOException {\n   InputStream inputStream = WordUtil.class.getClassLoader().getResourceAsStream(\"templates\/docxTemplate.docx\");\n}\n<\/pre>\n\n\n\n<p><br>\u62ff\u5230\u6d41\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u5c06\u5176\u8f6c\u6362\u4e3a\u4efb\u610f\u4e00\u4e2a\u6211\u4eec\u9700\u8981\u7684\u5bf9\u8c61\uff0c\u6bd4\u5982<strong>File<\/strong>\u3001<strong>String<\/strong>\u7b49\u7b49\uff0c\u6b64\u5904\u6211\u8981\u83b7\u53d6<strong>docxTemplate.docx<\/strong>\u4e0b\u7684\u76ee\u5f55\u7ed3\u6784\uff0c\u56e0\u6b64\u6211\u9700\u8981\u4e00\u4e2a<strong>File<\/strong>\u5bf9\u8c61\uff0c\u4ee3\u7801\u4e3e\u4f8b\u5982\u4e0b\uff1a<\/p>\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=\"\">import org.apache.commons.io.FileUtils;\n \n   public static void main(String[] args) throws IOException {\n        InputStream inputStream = WordUtil.class.getClassLoader().getResourceAsStream(\"templates\/docxTemplate.docx\");\n        File docxFile = new File(\"docxTemplate.docx\");\n        \/\/ \u4f7f\u7528common-io\u7684\u5de5\u5177\u7c7b\u5373\u53ef\u8f6c\u6362\n        FileUtils.copyToFile(inputStream,docxFile);\n        ZipFile zipFile = new ZipFile(docxFile);\n        Enumeration&lt;? extends ZipEntry> zipEntrys = zipFile.entries();\n        \/\/ todo \u8bb0\u5f97\u5173\u95ed\u6d41\n    }<\/pre>\n\n\n\n<p>pom.xml<\/p>\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=\"\">    &lt;dependency>\n    \t&lt;groupId>commons-io&lt;\/groupId>\n    \t&lt;artifactId>commons-io&lt;\/artifactId>\n    \t&lt;version>2.11.0&lt;\/version>\n    &lt;\/dependency>\n  &lt;\/dependencies><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u7ed3\u679c<\/h5>\n\n\n\n<p>\u6253\u5305\u3001\u53d1\u5e03\u81f3beta\u73af\u5883\uff0c\u4eb2\u6d4b\u53ef\u7528\uff0c\u95ee\u9898\u5b8c\u7f8e\u89e3\u51b3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 SpringBoot\u5fae\u670d\u52a1\u5df2\u6210\u4e3a\u4e1a\u754c\u4e3b\u6d41\uff0c\u4ece\u5f00\u53d1\u5230\u90e8\u7f72\u90fd\u975e\u5e38\u7701\u65f6\u7701\u529b\uff0c\u4f46\u662f\u6700\u8fd1\u5c0f\u660e\u5f00\u53d1\u65f6\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff1a\u5728 [&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\/4856"}],"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=4856"}],"version-history":[{"count":3,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4856\/revisions"}],"predecessor-version":[{"id":4860,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4856\/revisions\/4860"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}