{"id":2367,"date":"2023-06-27T15:33:04","date_gmt":"2023-06-27T07:33:04","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=2367"},"modified":"2023-06-27T15:33:04","modified_gmt":"2023-06-27T07:33:04","slug":"springboot-%e5%ae%9e%e7%8e%b0%e5%a4%a7%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0%e4%b8%8b%e8%bd%bd%e3%80%81%e5%88%86%e7%89%87%e3%80%81%e6%96%ad%e7%82%b9%e7%bb%ad%e4%bc%a0","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/springboot-%e5%ae%9e%e7%8e%b0%e5%a4%a7%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0%e4%b8%8b%e8%bd%bd%e3%80%81%e5%88%86%e7%89%87%e3%80%81%e6%96%ad%e7%82%b9%e7%bb%ad%e4%bc%a0\/","title":{"rendered":"SpringBoot \u5b9e\u73b0\u5927\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u3001\u5206\u7247\u3001\u65ad\u70b9\u7eed\u4f20"},"content":{"rendered":"<div class='wxsyncmain'>\n<section data-tool=\"mdnice\u7f16\u8f91\u5668\" data-website=\"https:\/\/www.mdnice.com\">\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\">\u5927\u5bb6\u597d\uff0c\u6211\u662f\u4e00\u5b89\uff0c\u4eca\u5929\u804a\u4e00\u4e0bspringboot\u5982\u4f55\u5b9e\u73b0\u5927\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u3001\u5206\u7247\u3001\u65ad\u70b9\u7eed\u4f20<\/h2>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding: 0px;font-weight: bold;color: black;font-size: 22px;line-height: 1.5em;margin-top: 2.2em;margin-bottom: 35px;\"><span style=\"display: inline-block;font-weight: bold;background: linear-gradient(#fff 60%, #ffb11b 40%);color: #515151;padding: 2px 13px 2px;margin-right: 3px;height: 50%;\">\u5b9e\u73b0\u601d\u8def<\/span><\/h2>\n<ul data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;color: black;list-style-type: disc;\" class=\"list-paddingleft-1\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\">\n<p style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0 0 20px;padding: 0;line-height: 1.8em;color: #3a3a3a;\">\u5206\u7247\uff1a\u6309\u7167\u81ea\u5b9a\u4e49\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u5c06\u5927\u6587\u4ef6\u5206\u6210\u591a\u4e2a\u5c0f\u6587\u4ef6\u7247\u6bb5\u3002<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\">\n<p style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0 0 20px;padding: 0;line-height: 1.8em;color: #3a3a3a;\">\u65ad\u70b9\u7eed\u4f20\uff1a\u6839\u636e\u5206\u7247\u6570\u91cf\uff0c\u7ed9\u6bcf\u4e2a\u5c0f\u6587\u4ef6\u901a\u8fc7\u5faa\u73af\u8d77\u5bf9\u5e94\u540d\u79f0\uff0c\u5f53\u6587\u4ef6\u4e0b\u8f7d\u4e2d\u65ad\u5728\u7eed\u4f20\u65f6\uff0c\u5224\u65ad\u5c0f\u6587\u4ef6\u540d\u79f0\u82e5\u5b58\u5728\u5219\u4e0d\u5b58\u4e86\uff0c\u6b64\u65f6\u8fd8\u9700\u8981\u5224\u65ad\u6587\u4ef6\u82e5\u4e0d\u662f\u6700\u540e\u4e00\u4e2a\u5206\u7247\u5219\u5927\u5c0f\u4e3a\u7f13\u51b2\u533a\u56fa\u5b9a\u5927\u5c0f\uff0c\u82e5\u6ca1\u8fbe\u5230\u5219\u8bc1\u660e\u5c0f\u6587\u4ef6\u6ca1\u4f20\u5b8c\u9700\u8981\u91cd\u65b0\u4f20\u8f93\u3002<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\">\n<p style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0 0 20px;padding: 0;line-height: 1.8em;color: #3a3a3a;\">\u5408\u5e76\uff1a\u4e0b\u8f7d\u65f6\u901a\u8fc7\u7ebf\u7a0b\u6c60\u521b\u5efa\u4efb\u52a1\u8fdb\u884c\u4e0b\u8f7d\u6216\u4e0a\u4f20\u3001\u5f53\u5224\u65ad\u6700\u540e\u4e00\u4e2a\u5206\u7247\u4f20\u5b8c\u65f6\uff0c\u8c03\u7528\u5408\u5e76\u65b9\u6cd5\uff0c\u6839\u636e\u4e4b\u524d\u5b9a\u4e49\u7684\u6587\u4ef6\u540d\u79f0\u987a\u5e8f\u8fdb\u884c\u5408\u5e76\uff0c\u80af\u80fd\u51fa\u73b0\u6700\u540e\u4e00\u4e2a\u5206\u7247\u4f20\u5b8c\uff0c\u4e4b\u524d\u5206\u7247\u672a\u4f20\u5b8c\u7684\u60c5\u51b5\uff0c\u9700\u8981\u4f7f\u7528while\u5faa\u73af\u8fdb\u884c\u5224\u65ad\uff0c\u591a\u6587\u4ef6\u672a\u4f20\u8f93\u5b8c\uff0c\u5219\u7b49\u5f85\u4e00\u4f1a\u7ee7\u7eed\u5224\u65ad\u3002<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\">\n<p style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0 0 20px;padding: 0;line-height: 1.8em;color: #3a3a3a;\">\u5927\u6587\u4ef6\u79d2\u4f20\uff1a\u5b9e\u9645\u4e0a\u662f\u6839\u636e\u6587\u4ef6\u540d\u79f0\u533a\u4e00\u4e2a\u552f\u4e00\u7684md5\u503c\u5b58\u50a8\uff0c\u4f20\u6587\u4ef6\u65f6\u8fdb\u884c\u5224\u65ad\uff0c\u82e5\u5b58\u5728\u5219\u4e0d\u4f20\u3002<\/p>\n<\/section>\n<\/li>\n<\/ul>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 20px;line-height: 1.4;padding-top: 10px;margin: 10px 0 5px;\"><span style=\"display: none;\"><\/span><span style=\"color: #515151;font-weight: 700;font-size: 1.0em;padding-left: 20px;border-left: 3px solid #f9bf45;\">\u521b\u5efaspringboot\u9879\u76ee\uff0c\u6dfb\u52a0\u4f9d\u8d56<\/span><span style=\"display: none;\"><\/span><\/h3>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background: url(&quot;https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152250650.jpeg&quot;) 10px 10px \/ 40px no-repeat rgb(40, 44, 52);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;\"><\/span><code style=\"overflow-x: auto;padding: 16px;color: #abb2bf;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #282c34;border-radius: 5px;\">@RestController<br  \/>public&nbsp;class&nbsp;DownloadClient&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;final&nbsp;static&nbsp;long&nbsp;per_page&nbsp;=&nbsp;1024l*1024l*50l;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5206\u7247\u5b58\u50a8\u4e34\u65f6\u76ee\u5f55&nbsp;\u5f53\u5206\u7247\u4e0b\u8f7d\u5b8c\u540e\u5728\u76ee\u5f55\u4e2d\u627e\u5230\u6587\u4ef6\u5408\u5e76<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;final&nbsp;static&nbsp;String&nbsp;down_path=<span style=\"color: #98c379;line-height: 26px;\">\"D:\\File\"<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u591a\u7ebf\u7a0b\u4e0b\u8f7d<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;ExecutorService&nbsp;pool&nbsp;=&nbsp;&nbsp;Executors.newFixedThreadPool(10);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u6587\u4ef6\u5927\u5c0f&nbsp;\u5206\u7247\u6570\u91cf&nbsp;\u6587\u4ef6\u540d\u79f0<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u4f7f\u7528\u63a2\u6d4b&nbsp;\u83b7\u53d6\u53d8\u91cf<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u4f7f\u7528\u591a\u7ebf\u7a0b\u5206\u7247\u4e0b\u8f7d<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u6700\u540e\u4e00\u4e2a\u5206\u7247\u4e0b\u8f7d\u5b8c&nbsp;\u5f00\u59cb\u5408\u5e76<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;@RequestMapping(<span style=\"color: #98c379;line-height: 26px;\">\"\/downloadFile\"<\/span>)<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;String&nbsp;downloadFile()&nbsp;throws&nbsp;IOException&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInfo&nbsp;fileInfo&nbsp;=&nbsp;download(0,10,-1,null);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">if<\/span>&nbsp;(fileInfo!=&nbsp;null){<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;pages&nbsp;=&nbsp;fileInfo.fSize\/per_page;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">for<\/span>&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;=&nbsp;pages;&nbsp;i++)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool.submit(new&nbsp;Download(i*per_page,(i+1)*per_page-1,i,fileInfo.fName));<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #e6c07b;line-height: 26px;\">return<\/span>&nbsp;<span style=\"color: #98c379;line-height: 26px;\">\"\u6210\u529f\"<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;class&nbsp;Download&nbsp;implements&nbsp;Runnable{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;start;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;end;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;page;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;fName;<br  \/>&nbsp;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;Download(long&nbsp;start,&nbsp;long&nbsp;end,&nbsp;long&nbsp;page,&nbsp;String&nbsp;fName)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.start&nbsp;=&nbsp;start;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.end&nbsp;=&nbsp;end;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.page&nbsp;=&nbsp;page;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.fName&nbsp;=&nbsp;fName;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: #61aeee;line-height: 26px;\">run<\/span><\/span>()&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInfo&nbsp;fileInfo&nbsp;=&nbsp;download(start,end,page,fName);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(IOException&nbsp;e)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u8fd4\u56de\u6587\u4ef6\u540d&nbsp;\u8ddf\u5927\u5c0f<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;FileInfo&nbsp;download(long&nbsp;start,long&nbsp;end,long&nbsp;page,String&nbsp;fName)&nbsp;throws&nbsp;IOException&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u65ad\u70b9\u4e0b\u8f7d&nbsp;\u6587\u4ef6\u5b58\u5728\u4e0d\u9700\u8981\u4e0b\u8f7d<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File&nbsp;file&nbsp;=&nbsp;new&nbsp;File(down_path,&nbsp;page&nbsp;+&nbsp;<span style=\"color: #98c379;line-height: 26px;\">\"-\"<\/span>&nbsp;+&nbsp;fName);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u63a2\u6d4b\u5fc5\u987b\u653e\u884c&nbsp;\u82e5\u4e0b\u8f7d\u5206\u7247\u53ea\u4e0b\u8f7d\u4e00\u534a\u5c31\u953b\u70bc\u9700\u8981\u91cd\u65b0\u4e0b\u8f7d\u6240\u4ee5\u9700\u8981\u5224\u65ad\u6587\u4ef6\u662f\u5426\u5b8c\u6574<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">if<\/span>&nbsp;(file.exists()&amp;&amp;page&nbsp;!=&nbsp;-1&amp;&amp;file.length()==per_page){<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #e6c07b;line-height: 26px;\">return<\/span>&nbsp;null;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u9700\u8981\u77e5\u9053&nbsp;&nbsp;\u5f00\u59cb-\u7ed3\u675f&nbsp;=&nbsp;\u5206\u7247\u5927\u5c0f<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpClient&nbsp;client&nbsp;=&nbsp;HttpClients.createDefault();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/httpclient\u8fdb\u884c\u8bf7\u6c42<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpGet&nbsp;httpGet&nbsp;=&nbsp;new&nbsp;HttpGet(<span style=\"color: #98c379;line-height: 26px;\">\"http:\/\/127.0.0.1:8080\/down\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u544a\u8bc9\u670d\u52a1\u7aef\u505a\u5206\u7247\u4e0b\u8f7d<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;httpGet.setHeader(<span style=\"color: #98c379;line-height: 26px;\">\"Range\"<\/span>,<span style=\"color: #98c379;line-height: 26px;\">\"bytes=\"<\/span>+start+<span style=\"color: #98c379;line-height: 26px;\">\"-\"<\/span>+end);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpResponse&nbsp;response&nbsp;=&nbsp;client.execute(httpGet);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;fSize&nbsp;=&nbsp;response.getFirstHeader(<span style=\"color: #98c379;line-height: 26px;\">\"fSize\"<\/span>).getValue();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fName=&nbsp;URLDecoder.decode(response.getFirstHeader(<span style=\"color: #98c379;line-height: 26px;\">\"fName\"<\/span>).getValue(),<span style=\"color: #98c379;line-height: 26px;\">\"utf-8\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpEntity&nbsp;entity&nbsp;=&nbsp;response.getEntity();\/\/\u83b7\u53d6\u6587\u4ef6\u6d41\u5bf9\u8c61<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;is&nbsp;=&nbsp;entity.getContent();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u4e34\u65f6\u5b58\u50a8\u5206\u7247\u6587\u4ef6<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileOutputStream&nbsp;fos&nbsp;=&nbsp;new&nbsp;FileOutputStream(file);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[]&nbsp;buffer&nbsp;=&nbsp;new&nbsp;byte[1024];\/\/\u5b9a\u4e49\u7f13\u51b2\u533a<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;ch;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">while<\/span>&nbsp;((ch&nbsp;=&nbsp;is.read(buffer))&nbsp;!=&nbsp;-1){<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fos.write(buffer,0,ch);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fos.flush();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fos.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5224\u65ad\u662f\u4e0d\u662f\u6700\u540e\u4e00\u4e2a\u5206\u7247<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">if<\/span>&nbsp;(end-Long.valueOf(fSize)&gt;0){<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5408\u5e76<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mergeFile(fName,page);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(Exception&nbsp;e)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #e6c07b;line-height: 26px;\">return<\/span>&nbsp;new&nbsp;FileInfo(Long.valueOf(fSize),fName);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;void&nbsp;mergeFile(String&nbsp;fName,&nbsp;long&nbsp;page)&nbsp;throws&nbsp;Exception&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5f52\u5e76\u6587\u4ef6\u4f4d\u7f6e<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File&nbsp;file&nbsp;=&nbsp;new&nbsp;File(down_path,&nbsp;fName);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BufferedOutputStream&nbsp;os&nbsp;=&nbsp;new&nbsp;BufferedOutputStream(new&nbsp;FileOutputStream(file));<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">for<\/span>&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;=&nbsp;page;&nbsp;i++)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File&nbsp;tempFile&nbsp;=&nbsp;new&nbsp;File(down_path,&nbsp;i&nbsp;+&nbsp;<span style=\"color: #98c379;line-height: 26px;\">\"-\"<\/span>&nbsp;+&nbsp;fName);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5206\u7247\u6ca1\u4e0b\u8f7d\u6216\u8005\u6ca1\u4e0b\u8f7d\u5b8c\u9700\u8981\u7b49\u5f85<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">while<\/span>&nbsp;(!file.exists()||(i!=page&amp;&amp;tempFile.length()&lt;per_page)){<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(100);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[]&nbsp;bytes&nbsp;=&nbsp;FileUtils.readFileToByteArray(tempFile);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;os.write(bytes);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;os.flush();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tempFile.delete();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File&nbsp;file1&nbsp;=&nbsp;new&nbsp;File(down_path,&nbsp;-1&nbsp;+&nbsp;<span style=\"color: #98c379;line-height: 26px;\">\"-null\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file1.delete();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;os.flush();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;os.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u4f7f\u7528\u5185\u90e8\u7c7b\u5b9e\u73b0<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;class&nbsp;FileInfo{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;fSize;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;fName;<br  \/>&nbsp;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;FileInfo(long&nbsp;fSize,&nbsp;String&nbsp;fName)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.fSize&nbsp;=&nbsp;fSize;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.fName&nbsp;=&nbsp;fName;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><\/code><\/pre>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\"><br  \/><\/pre>\n<section data-tool=\"mdnice\u7f16\u8f91\u5668\" data-website=\"https:\/\/www.mdnice.com\" style=\"padding: 0 10px;line-height: 1.6;word-spacing: 0px;letter-spacing: 0px;word-break: break-word;word-wrap: break-word;text-align: left;font-size: 16px;margin-top: -1em;color: #333;padding-top: 0;padding-bottom: 0;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#39;PingFang SC&#39;, Cambria, Cochin, Georgia, Times, &#39;Times New Roman&#39;, serif;\">\n<blockquote data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"border-top: none;border-right: none;border-bottom: none;display: block;font-size: 0.9em;overflow: auto;color: rgb(106, 115, 125);margin-bottom: 20px;margin-top: 20px;background: none;border-left: 4px solid rgb(221, 221, 221);padding: 0px 1em;line-height: 1.6 !important;\">\n<p style=\"padding: 0px;font-size: inherit;margin: 0px;color: rgb(102, 102, 102);text-align: right;line-height: 1.6 !important;\">\u4f5c\u8005\uff1a\u8fdc\u8d70\u4e0e\u68a6\u6e38<\/p>\n<p style=\"padding: 0px;font-size: inherit;margin: 0px;color: rgb(102, 102, 102);line-height: 1.6 !important;text-align: right;\">&nbsp;https:\/\/blog.csdn.net\/weixin_5221055<\/p>\n<\/blockquote>\n<\/section>\n<blockquote data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"border-top: none;border-right: none;border-bottom: none;display: block;font-size: 0.9em;overflow: auto;border-left: 3px solid rgb(255, 177, 27);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;background: rgb(255, 245, 227);\">\n<p style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;padding: 0;margin: 0px;line-height: 26px;color: #595959;\">\u6700\u540e\u8bf4\u4e00\u53e5\uff08\u522b\u767d\u5ad6\uff0c\u6c42\u5173\u6ce8\uff09<\/p>\n<\/blockquote>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0 0 20px;padding: 0;line-height: 1.8em;color: #3a3a3a;\">\u5982\u679c\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u6216\u8005\u6709\u6240\u542f\u53d1\u7684\u8bdd\uff0c\u5e2e\u5fd9\u70b9\u8d5e\u3001\u5728\u770b\u3001\u8f6c\u53d1\u3001\u6536\u85cf\uff0c\u4f60\u7684\u652f\u6301\u5c31\u662f\u6211\u575a\u6301\u4e0b\u53bb\u7684\u6700\u5927\u52a8\u529b\uff01<img decoding=\"async\" class=\"lazyload\"data-ratio=\"1\" data-type=\"png\" data-w=\"20\" style=\"display: inline-block;width: 20px;vertical-align: text-bottom;height: auto !important;\"  data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152248812.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"  \/><noscript><img decoding=\"async\" data-ratio=\"1\" data-type=\"png\" data-w=\"20\" style=\"display: inline-block;width: 20px;vertical-align: text-bottom;height: auto !important;\"  src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152248812.png\"  \/><\/noscript><img decoding=\"async\" class=\"lazyload\"data-ratio=\"1\" data-type=\"png\" data-w=\"20\" style=\"display: inline-block;width: 20px;vertical-align: text-bottom;height: auto !important;\"  data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152249838.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"  \/><noscript><img decoding=\"async\" data-ratio=\"1\" data-type=\"png\" data-w=\"20\" style=\"display: inline-block;width: 20px;vertical-align: text-bottom;height: auto !important;\"  src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152249838.png\"  \/><\/noscript><img decoding=\"async\" class=\"lazyload\"data-ratio=\"1\" data-type=\"png\" data-w=\"20\" style=\"display: inline-block;width: 20px;vertical-align: text-bottom;height: auto !important;\"  data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152249393.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"  \/><noscript><img decoding=\"async\" data-ratio=\"1\" data-type=\"png\" data-w=\"20\" style=\"display: inline-block;width: 20px;vertical-align: text-bottom;height: auto !important;\"  src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152249393.png\"  \/><\/noscript><\/p>\n<section class=\"mp_profile_iframe_wrp\"><mpprofile class=\"custom_select_card mp_profile_iframe\" data-id=\"Mzg5MzgxMTIyOQ==\" data-headimg=\"http:\/\/mmbiz.qpic.cn\/mmbiz_png\/QzI3807PeUlUKxuueCHNuNOXehciaM7OXnvr0pprJIAVYOs3hiaYh5JLyrcShyLJQ8iaqjyRPJPf1Pz4v4T6j1Fxw\/0?wx_fmt=png\" data-nickname=\"\u4e00\u5b89\u672a\u6765\" data-alias=\"\" data-signature=\"\u81f4\u529b\u4e8ejava\uff0c\u5927\u6570\u636e\uff1b\u5fc3\u5f97\u4ea4\u6d41\uff0c\u6280\u672f\u5206\u4eab\uff1b\" data-pluginname=\"mpprofile\" data-from=\"0\"><\/mpprofile><\/section>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0 0 20px;padding: 0;line-height: 1.8em;color: #3a3a3a;\"><br  \/><\/p>\n<\/section>\n<blockquote>\n<p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7:                 \u4e00\u5b89\u672a\u6765              <\/p>\n<\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u4e00\u5b89\uff0c\u4eca\u5929\u804a\u4e00\u4e0bspringboot\u5982\u4f55\u5b9e\u73b0\u5927\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u3001\u5206\u7247\u3001\u65ad\u70b9\u7eed\u4f20 \u5b9e\u73b0\u601d\u8def \u5206\u7247\uff1a\u6309\u7167\u81ea\u5b9a\u4e49\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u5c06\u5927 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":2362,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-2367","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152247664-150x150.jpeg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152248812.png","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152247664-300x128.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152247664-1024x435.jpeg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152248812.png","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152247664-300x128.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152247664-1024x435.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152247664.jpeg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152248812.png","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152248812.png","id":"image1"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152249838.png","id":"image2"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152249838.png","id":"image3"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152249393.png","id":"image4"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/06\/20230627152249393.png","id":"image5"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","post_date":"2023-06-27","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":486,"next_post_id":2603,"next_post_title":"SpringBoot bean\u81ea\u52a8\u88c5\u914d\u539f\u7406\uff0c\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86\uff01","previous_post_id":2334,"previous_post_title":"Spring Boot + Mybatis Plus + ClickHouse \u8f7b\u677e\u5b9e\u73b0\u589e\u5220\u6539\u67e5\uff0c\u770b\u4e86\u5fc5\u61c2\uff01","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2367"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2367\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/2362"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}