当前位置: 首页 > news >正文

大良招聘网站建设如何下载字体到wordpress

大良招聘网站建设,如何下载字体到wordpress,建设企业网站登录入口,网上商店系统设计与开发Sptingboot项目 — maven打包#xff0c;云效#xff0c;docker#xff0c;k8s 场景 — 导出excel模板 问题 1.乱码 2.下载为0KB#xff0c;打开没有数据 模板内容 测试代码 测试方法 方法过程结果问题原因将文件直接放到服务器使用接口下载数据正常,排除文件问题排…Sptingboot项目 — maven打包云效dockerk8s 场景 — 导出excel模板 问题 1.乱码 2.下载为0KB打开没有数据 模板内容 测试代码 测试方法 方法过程结果问题原因将文件直接放到服务器使用接口下载数据正常,排除文件问题排除接口问题文件问题文件放到resource目录下使用接口下载下载乱码使用相同接口下载乱码猜测是maven编译问题文件移出到resouce目录外使用接口下载下载为0KB使用相同接口下载乱码猜测是maven编译问题 代码 InputStream inputStream null;ServletOutputStream servletOutputStream null;try {//注意修改目录Resource resource new DefaultResourceLoader().getResource(classpath:file/goods_import.xls);response.setContentType(application/force-download);response.setHeader(Content-Disposition, attachment;fileName new String(goods_import.getBytes(), StandardCharsets.ISO_8859_1) .xls);inputStream resource.getInputStream();servletOutputStream response.getOutputStream();IOUtils.copy(inputStream, servletOutputStream);response.flushBuffer();} catch (Exception e) {log.error(下载批量上传用户模板文件错误, e);} finally {try {if (servletOutputStream ! null) {servletOutputStream.close();}if (inputStream ! null) {inputStream.close();}} catch (Exception e) {log.error(下载批量上传用户模板文件错误, e);}}过程-可以跳过直接看解决办法 — 遵循网上的办法使用字节流设置字节大小设置编码都测试过一遍。 设置字节大小InputStream inputStream getClass().getClassLoader().getResourceAsStream(classpath:file/goods_import.xls);File file new File(goods_import.xls); // 指定下载文件的路径和名称try (OutputStream outputStream new FileOutputStream(file)) {// 将inputStream中的数据写入到outputStream中‌确保文件不为0KBbyte[] buffer new byte[1024];int bytesRead;while ((bytesRead inputStream.read(buffer)) ! -1) {outputStream.write(buffer, 0, bytesRead);}} catch (IOException e) {e.printStackTrace(); // 处理异常}finally {if (file.exists()){file.delete();}}设置字符集编码 response.setContentType(application/vnd.openxmlformats-officedocument.spreadsheetml.sheet);response.setHeader(Content-Disposition, attachment; filename\ file/goods_import.xls \);//这里设置为GBKUTF-8都不行response.setCharacterEncoding(GBK);try (BufferedInputStream inputStream new BufferedInputStream(ImportBusiness.class.getClassLoader().getResourceAsStream(file/goods_import.xls));OutputStream outputStream response.getOutputStream()) {if (inputStream null) {// 处理文件未找到的情况response.sendError(HttpServletResponse.SC_NOT_FOUND, File not found);return;}byte[] buffer new byte[1024];int bytesRead;while ((bytesRead inputStream.read(buffer)) ! -1) {outputStream.write(buffer, 0, bytesRead);}outputStream.flush();} catch (IOException e) {// 处理IO异常response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, IO error);}使用字节流输出 /*** 模板下载*/public void downloadTemplate(HttpServletResponse response) {OutputStream out null;InputStream in null;ByteArrayOutputStream bos null;String fileName good_import;try {// 读取模板Resource res new ClassPathResource(classpath:file/goods_import.xls);XSSFWorkbook workbook new XSSFWorkbook(res.getInputStream());// 转换为字节流bos new ByteArrayOutputStream();workbook.write(bos);byte[] barray bos.toByteArray();in new ByteArrayInputStream(barray);response.reset();response.setContentType(application/octet-stream);response.addHeader(Content-Disposition, attachment;filename URLEncoder.encode(fileName, UTF-8) .xls);out response.getOutputStream();byte[] b new byte[1024];int len;while ((len in.read(b)) 0) {out.write(b, 0, len);}out.flush();} catch (Exception e) {log.error(下载模板失败, e);} finally {if (null ! in) {try {in.close();} catch (IOException e) {log.error(关闭资源异常, e);}}if (null ! out) {try {out.close();} catch (IOException e) {log.error(关闭资源异常, e);}}if (null ! bos) {try {bos.flush();bos.close();} catch (IOException e) {log.error(关闭资源异常, e);}}}}经测试以上方法均不行然后考虑到jar打包会被编译会不会是这个导致的呢。能不能忽略掉这个xls文件呢 这里使用maven打包,使用提供的插件排除如下 plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-resources-plugin/artifactIdversion3.2.0/versionconfigurationnonFilteredFileExtensionsnonFilteredFileExtensionxlsx/nonFilteredFileExtensionnonFilteredFileExtensionxls/nonFilteredFileExtension/nonFilteredFileExtensions/configuration/plugin重新调用接口下载文件正常
http://www.dnsts.com.cn/news/97749.html

相关文章:

  • 做简单网站视频模板网站
  • 安徽网站建设科技html代码怎么变成网页
  • 河南建设网站官网营销方式
  • 亚马逊网站风格青岛专业网站设计的公司
  • 网站图片不是本站的对seo有什么不好房屋装修设计师怎么收费
  • 西安免费网站搭建制作成都网站制作收费
  • 政务网站建设规范wordpress与dz
  • 自己怎么做商城网站吗做网站的电话号码
  • 定制制作网站哪家好大连旅顺口区房价
  • 济宁企业做网站wordpress主题预览
  • 外贸做哪个网站好介绍好的免费网站模板下载
  • 网站模块建设中网站不被收录
  • 侗族网站建设网站建设基础策划
  • 夏津网站建设价格做外贸如何分析客户网站
  • 山东建设企业网站现在找个网站这么难的吗
  • 天津做网站印标专门培训seo的网站
  • wordpress网站源代码一个空间2个网站代码
  • 长沙装修公司口碑比较好的wordpress主题 SEO优化
  • 软件开发流程图绘制杭州网站优化公司
  • 临沂网站设计制作wordpress iis 中文乱码
  • 如何写代码做网站6做网站换服务器怎么整
  • 合肥企业网站建设专家白酒网站定制开发
  • 网站建设方案是什么山东能源集团 网站建设
  • 百度右边的网站推荐怎么做的青岛做网站价格
  • 关于茶叶的网站模板免费下载网络游戏推广员是做什么的
  • 电脑网站设计制作做网站在线支付系统多少钱?
  • 网站建站的步骤施工企业筹备建立
  • 建立网站有免费的吗龙之向导外贸经理人网站
  • 如何制作一个游戏app网站优化标签
  • 网站建设用到的软件推广宣传方式有哪些