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

织梦商城网站模板河北邢台特产

织梦商城网站模板,河北邢台特产,做车展的网站,优化英文业务场景#xff1a;因为公司会对excel文档加密#xff0c;通过svn或者git上传代码也会对文档进行加密#xff0c;所以这里将文档后缀去了#xff0c;这样避免文档加密。 实现思路#xff1a;将文档去掉后缀#xff0c;放入resources下#xff0c;获取输入流#xff0…业务场景因为公司会对excel文档加密通过svn或者git上传代码也会对文档进行加密所以这里将文档后缀去了这样避免文档加密。 实现思路将文档去掉后缀放入resources下获取输入流最后加上后缀前端成功下载 效果图 上代码 package com.***.util;import cn.hutool.core.util.StrUtil; import org.springframework.core.io.ClassPathResource;import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.BufferedInputStream; import java.io.File; import java.io.InputStream; import java.io.OutputStream; import java.net.URLEncoder;/*** author longwei* Description excel帮助类* date 2023/8/30 14:36*/ public class ExcelUtils {/*** 从静态资源下载文件** param fileName 文件名,没有后缀* param suffix 文件后缀* param request request* param response response*/public static void downloadFileByLocalPath(HttpServletRequest request, HttpServletResponse response,String fileName, String suffix) throws Exception {if (StrUtil.isEmpty(fileName) || StrUtil.isEmpty(suffix)) {throw new RuntimeException(文件信息不能为空);}InputStream inputStream new ClassPathResource(file File.separator fileName).getInputStream();fileName fileName suffix;downFileByInputStream(request, response, inputStream, fileName);}public static void downFileByInputStream(HttpServletRequest request, HttpServletResponse response, InputStream inputStream, String fileName) throws Exception {byte[] buffer new byte[1024];BufferedInputStream bis null;OutputStream os null;String finalFileName;try {final String userAgent request.getHeader(USER-AGENT);//IE浏览器if (StrUtil.contains(userAgent, MSIE) || StrUtil.contains(userAgent, Trident)) {finalFileName URLEncoder.encode(fileName, UTF8);}//google,火狐浏览器else if (StrUtil.contains(userAgent, Mozilla)) {finalFileName new String(fileName.getBytes(), ISO8859-1);}//其他浏览器else {finalFileName URLEncoder.encode(fileName, UTF8);}response.setCharacterEncoding(UTF-8);// 设置强制下载不打开response.setContentType(application/force-download);// 设置文件名response.addHeader(Content-Disposition, attachment;fileName finalFileName);bis new BufferedInputStream(inputStream);os response.getOutputStream();int i bis.read(buffer);while (i ! -1) {os.write(buffer, 0, i);i bis.read(buffer);}} catch (Exception e) {e.printStackTrace();} finally {if (inputStream ! null) {try {inputStream.close();} catch (Exception e) {e.printStackTrace();}}if (bis ! null) {try {bis.close();} catch (Exception e) {e.printStackTrace();}}if (os ! null) {try {os.flush();os.close();} catch (Exception e) {e.printStackTrace();}}}}}controller层 RequestMapping(/downloadTemplate)public void downloadTemplate(HttpServletRequest request, HttpServletResponse response) {breedInfoService.downloadTemplate(request, response);}service.impl层这里直接用ExcelUtils方法 Overridepublic void downloadTemplate(HttpServletRequest request, HttpServletResponse response) {String fileName 中药饮片导入模板;try {ExcelUtils.downloadFileByLocalPath(request, response, fileName, .xlsx);} catch (Exception e) {log.error(下载中药饮片导入模板失败-{}, e.getMessage());throw new BusinessException(下载中药饮片导入模板失败,请联系管理员);}}
http://www.yutouwan.com/news/211579/

相关文章:

  • 南通企业网站公司策划是做什么的
  • 在线销售型网站产品蓬莱做网站那家好
  • 网站同时使用asp php钢结构招聘网最新招聘信息
  • 微网站是免费的吗页面跳转自动更新
  • 怎么给网站做链接屏蔽微信网址
  • 青岛大型门户网站建设推广南京房地产网站建设
  • 张家口北京网站建设打不开网站怎么办
  • 郑州网站建设费用滴道网站建设
  • 网站开发自学网校园文化建设
  • 东莞网站建设效果淘宝网网页版登录官网登录
  • 怎么从网站知道谁做的公司网站网页设计
  • 厦门无忧网站建设有限公司六安网络推广
  • 如何做网站咨询wordpress 上传类型
  • 上海做外贸建站的专业公司pc端自定义页设计与制作
  • 网站设计欣赏移动h5页面制作工具 软件
  • 淘宝网站怎么做的苏州建网站要多少钱
  • 深圳福田专业网站推广玉山网站制作
  • 桐庐县建设局网站关于实验室建设的英文网站
  • 如何用二级域名做网站wordpress腾讯云cdn配置教程
  • 网页设计素材音乐嘉兴seo计费管理
  • 乐清做网站哪家好简述设计优秀电子商务网站的成功要素
  • 分类目录网站大全做seo仿牌网站服务器
  • 网站设计深圳联系电话?百度贴吧论坛
  • 防邪办网站建设方案文档seo专员是指什么意思
  • 网站建设氺金手指排名14写网站建设需求文档
  • 广州 济南网站建设公司 网络服务网站建设专员一定要会网站建设吗
  • 视频直播网站建设招聘信息网站建设
  • 制作app免费网站模板如何做百度推广网站
  • 影视文化传媒公司网站建设wordpress 显示文章摘要
  • 衡阳网站优化方案公司宣传册设计与制作公司