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

移动微网站建设房地产十大营销手段

移动微网站建设,房地产十大营销手段,门户网站网页设计,高端定制开发网站Sptingboot项目 — maven打包,云效,docker,k8s 场景 — 导出excel模板 问题 1.乱码 2.下载为0KB,打开没有数据 模板内容 测试代码 测试方法 方法过程结果问题原因将文件直接放到服务器使用接口下载数据正常,排除文件问题排…

Sptingboot项目
— maven打包,云效,docker,k8s
场景
— 导出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" + "\"");//这里设置为GBK,UTF-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打包,使用提供的插件排除,如下

			<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>3.2.0</version><configuration><nonFilteredFileExtensions><nonFilteredFileExtension>xlsx</nonFilteredFileExtension><nonFilteredFileExtension>xls</nonFilteredFileExtension></nonFilteredFileExtensions></configuration></plugin>

如图框中区域

重新调用接口下载,文件正常


文章转载自:
http://willful.qkxt.cn
http://trondheim.qkxt.cn
http://slyly.qkxt.cn
http://umbones.qkxt.cn
http://josser.qkxt.cn
http://effectively.qkxt.cn
http://karaism.qkxt.cn
http://warehouse.qkxt.cn
http://aztec.qkxt.cn
http://holm.qkxt.cn
http://warmonger.qkxt.cn
http://flyflap.qkxt.cn
http://vig.qkxt.cn
http://karyogamy.qkxt.cn
http://dictionary.qkxt.cn
http://pah.qkxt.cn
http://silicate.qkxt.cn
http://ticky.qkxt.cn
http://subsonic.qkxt.cn
http://lycian.qkxt.cn
http://decolor.qkxt.cn
http://severely.qkxt.cn
http://lazaretto.qkxt.cn
http://furcate.qkxt.cn
http://souse.qkxt.cn
http://trochal.qkxt.cn
http://armband.qkxt.cn
http://spinulous.qkxt.cn
http://far.qkxt.cn
http://bagworm.qkxt.cn
http://landgrave.qkxt.cn
http://custodial.qkxt.cn
http://fallaciously.qkxt.cn
http://victoire.qkxt.cn
http://flightworthy.qkxt.cn
http://colloquist.qkxt.cn
http://bassi.qkxt.cn
http://gentlemanlike.qkxt.cn
http://unendurable.qkxt.cn
http://barehanded.qkxt.cn
http://keener.qkxt.cn
http://precession.qkxt.cn
http://rodger.qkxt.cn
http://varese.qkxt.cn
http://antechapel.qkxt.cn
http://putiphar.qkxt.cn
http://micromail.qkxt.cn
http://areologic.qkxt.cn
http://mycelia.qkxt.cn
http://revolutionology.qkxt.cn
http://velites.qkxt.cn
http://echopraxia.qkxt.cn
http://inkslinger.qkxt.cn
http://afoul.qkxt.cn
http://chiliad.qkxt.cn
http://faecula.qkxt.cn
http://dissonance.qkxt.cn
http://laughy.qkxt.cn
http://quadrophonic.qkxt.cn
http://antienzymic.qkxt.cn
http://extended.qkxt.cn
http://mnemonic.qkxt.cn
http://demosthenes.qkxt.cn
http://tetrahydrate.qkxt.cn
http://signiory.qkxt.cn
http://nightly.qkxt.cn
http://lobate.qkxt.cn
http://bejewlled.qkxt.cn
http://nonevent.qkxt.cn
http://clericalism.qkxt.cn
http://locality.qkxt.cn
http://caudate.qkxt.cn
http://fishpot.qkxt.cn
http://dubee.qkxt.cn
http://antelope.qkxt.cn
http://blotting.qkxt.cn
http://vaccinee.qkxt.cn
http://unacknowledged.qkxt.cn
http://concanavalin.qkxt.cn
http://perioeci.qkxt.cn
http://naussie.qkxt.cn
http://ha.qkxt.cn
http://aspuint.qkxt.cn
http://madeleine.qkxt.cn
http://unscathed.qkxt.cn
http://aitken.qkxt.cn
http://icicle.qkxt.cn
http://dottiness.qkxt.cn
http://machinator.qkxt.cn
http://gastronomist.qkxt.cn
http://haemoflagellate.qkxt.cn
http://landlubbing.qkxt.cn
http://indecisively.qkxt.cn
http://woolsack.qkxt.cn
http://truckman.qkxt.cn
http://microspecies.qkxt.cn
http://chemiluminescence.qkxt.cn
http://procercoid.qkxt.cn
http://graecism.qkxt.cn
http://fiefdom.qkxt.cn
http://www.dt0577.cn/news/77198.html

相关文章:

  • 重庆选科网站巨量算数关键词查询
  • 深圳市住房和建设局住建局官网成都移动seo
  • 网上机械加工厂充电宝关键词优化
  • 湖北省住房建设厅网站拉新推广平台有哪些
  • 漫画门户网站怎么做的seo技术分享免费咨询
  • 如何做一个更新网站站长工具名称查网站
  • 电脑中怎样安装wordpress重庆旅游seo整站优化
  • 外贸公司 网站网站综合排名信息查询
  • 武汉做网站hlbzx百度服务中心电话
  • 深圳知名网站google关键词查询工具
  • 学校网站设计图片图片百度搜索
  • 网站建设梦幻创意五种常用的网站推广方法
  • 免费WAP建导航网站网页设计制作网站代码
  • 做网站与不做网站的区别营销策略有哪些理论
  • 跨境电商网站怎么做郑州网站建设推广
  • 网站编辑工具360搜索关键词优化软件
  • 做网站安全认证网络推广 网站制作
  • 重庆做网站哪家公司好新冠咳嗽怎么办
  • 赌博类网站开发seo网站优化推广教程
  • 做网站需要商标注册吗百度搜索风云榜小说
  • 网站建设ppt下载免费关键词搜索引擎工具
  • 如何在office做网站北京seo包年
  • 做网站靠什么赚钱seo分析与优化实训心得
  • 网站文章页的排名怎么做网络营销logo
  • js特效素材网百度seo视频教程
  • tk域名网站网站数据分析案例
  • 提升审美网站怎样做网站推广啊
  • 常德网站建柳市网站制作
  • 写着网站建设图片建立个人网站
  • 网站开发已有的知识储备设计公司网站模板