网站备案费用,批量外链工具,美食类网站开发需求,怎么做微信钓鱼网站resources 目录下放模板 excel 文件#xff0c;通过接口下载后#xff0c;可以正常下载#xff0c;但打不开。
问题#xff1a; springboot 项目简单的下载excel 模板功能#xff0c;模板放在resources/template/目录中
public void downloadItemBatch(HttpServletRespo…resources 目录下放模板 excel 文件通过接口下载后可以正常下载但打不开。
问题 springboot 项目简单的下载excel 模板功能模板放在resources/template/目录中
public void downloadItemBatch(HttpServletResponse response) throws IOException {String fileName 商品信息.xlsx;String path templates/ fileName;InputStream inputStream this.getClass().getClassLoader().getResourceAsStream(path);response.setContentType(application/vnd.ms-excel;charsetUTF-8);response.setHeader(Content-Disposition, attachment;filename URLEncoder.encode(fileName, UTF-8));ServletOutputStream outputStream response.getOutputStream();IOUtils.copy(inputStream, outputStream);outputStream.flush();outputStream.close();inputStream.close();}
代码挺简单一运行也挺顺利很快就把文件下好了。点开看看提示我可能是内存不足文件无法打开而且下载的文件比templates里的文件要大。
看了很多帖子试了很多方法最后发现pom文件里加个东西就行了
plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-resources-plugin/artifactIdversion2.7/versionconfigurationnonFilteredFileExtensions!--不加这一行xlsx文件会被过滤然后在maven build的时候去target下看对应的xlsx就是损坏的--nonFilteredFileExtensionxlsx/nonFilteredFileExtension/nonFilteredFileExtensions/configuration
/plugin
解决maven 构建时对该 excel 模板进行了过滤导致文件损坏解决办法在过滤的时候把 xlsx 排除掉(nonFilteredFileExtensionxlsx/nonFilteredFileExtension)。