zoukankan      html  css  js  c++  java
  • spring mvc 文件下载

    package com.clj.test.down.util;

    import java.io.File;
    import java.io.IOException;

    import org.apache.commons.io.FileUtils;
    import org.springframework.context.annotation.Scope;
    import org.springframework.http.HttpHeaders;
    import org.springframework.http.HttpStatus;
    import org.springframework.http.MediaType;
    import org.springframework.http.ResponseEntity;
    import org.springframework.stereotype.Component;
    import org.springframework.web.bind.annotation.RequestMapping;

    /**
    * <一句话功能简述>
    * <功能详细描述>
    *
    * @author Administrator
    * @version [版本号, 2014年3月7日]
    * @see [相关类/方法]
    * @since [产品/模块版本]
    */
    @Component
    @Scope("prototype")
    @RequestMapping("/downloadFile")
    public class DownloadAction
    {

    @RequestMapping("download")
    public ResponseEntity<byte[]> download() throws IOException {
    String path="D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\springMVC\WEB-INF\upload\图片10(定价后).xlsx";
    File file=new File(path);
    HttpHeaders headers = new HttpHeaders();
    String fileName=new String("你好.xlsx".getBytes("UTF-8"),"iso-8859-1");//为了解决中文名称乱码问题
    headers.setContentDispositionFormData("attachment", fileName);
    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
    headers, HttpStatus.CREATED);
    }
    }

  • 相关阅读:
    查看硬件的一些命令
    InfluxDB部署和使用
    利用mysql时间函数监控表中有没有当天数据
    js基础_for循环(学习笔记)
    JS基础_运算符的优先级
    JS基础_相等运算符
    Apache安装与卸载(win10系统测试)
    MySQL --添加环境变量教程
    MySQL安装教程及遇到的错误提示
    如何完全卸载MySQL
  • 原文地址:https://www.cnblogs.com/LWLDD/p/8714510.html
Copyright © 2011-2022 走看看