当前位置: 移动技术网 > IT编程>开发语言>Java > springboot下载excel模板

springboot下载excel模板

2018年10月17日  | 移动技术网IT编程  | 我要评论

成人小游戏调教女佣,无锡口碑网,口条男

在网上找了半天,获取springboot resource下面的文件,各种实验,最终解决了,废话不说直接上代码

 

/**
* 描述:下载外部案件导入模板
* @throws exception
*/
@requestmapping(value = "/downloadexcel")
@responsebody
public void downloadexcel(httpservletresponse res, httpservletrequest req,string name) throws exception {
       string filename = name+".xlsx";
    servletoutputstream out;
    res.setcontenttype("multipart/form-data");
    res.setcharacterencoding("utf-8");
    res.setcontenttype("text/html");
    string filepath = getclass().getresource("/template/" + filename).getpath();
    string useragent = req.getheader("user-agent");
  if (useragent.contains("msie") || useragent.contains("trident")) {
    filename = java.net.urlencoder.encode(filename, "utf-8");
  } else {
    // 非ie浏览器的处理:
         filename = new string((filename).getbytes("utf-8"), "iso-8859-1");
  }
  filepath = urldecoder.decode(filepath, "utf-8");
  res.setheader("content-disposition", "attachment;filename=" + filename);
  fileinputstream inputstream = new fileinputstream(filepath);
  out = res.getoutputstream();
  int b = 0;
  byte[] buffer = new byte[1024];
  while ((b = inputstream.read(buffer)) != -1) {
  // 4.写到输出流(out)中
  out.write(buffer, 0, b);
  }
  inputstream.close();

  if (out != null) {
  out.flush();
  out.close();
  }

}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网