import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils;
@RequestMapping(value = "/downLoadmoban",method = RequestMethod.GET)
public ResponseEntity<byte[]> downLoadmoban(HttpServletRequest request, HttpServletResponse response) throws IOException{
String rootpath = request.getSession().getServletContext().getRealPath("/muban");//获取项目中的模板文件夹
File file=new File(rootpath + File.separator + "ceshi.xls");
HttpHeaders headers = new HttpHeaders();
String fileName=new String("测试统计表导入模板.xls".getBytes("gb2312"),"iso-8859-1");//为了解决中文名称乱码问题
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"");
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
headers, HttpStatus.OK);
}
---------------------
【转载,仅作分享,侵删】
作者:小志的博客
原文:https://blog.csdn.net/li1325169021/article/details/85336606
版权声明:本文为博主原创文章,转载请附上博文链接!
|
|