博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring 框架ResponseEntity实现文件下载
阅读量:4029 次
发布时间:2019-05-24

本文共 606 字,大约阅读时间需要 2 分钟。

后台代码。@RequestMapping("downLoad")public ResponseEntity
downloadPromisePdf() { String fileName = "企业诚信守法承诺书.pdf"; try { byte[] pdf = **;//byte文件 String dfileName = new String(fileName.getBytes("gb2312"), "iso8859-1"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); headers.setContentDispositionFormData("attachment", dfileName); return new ResponseEntity<>(pdf, headers, HttpStatus.OK); } catch (BuzEx e){ logger.error( e.getMessage()); }catch (Exception e) { } return null;}

 

前端直接window.location.href='/downLoad';

转载地址:http://plvbi.baihongyu.com/

你可能感兴趣的文章
python:如何将excel文件转化成CSV格式
查看>>
Django 的Error: [Errno 10013]错误
查看>>
机器学习实战之决策树(一)
查看>>
[LeetCode By Python] 2 Add Two Number
查看>>
python 中的 if __name__=='__main__' 作用
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[LeetCode By Python]9. Palindrome Number
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]107. Binary Tree Level Order Traversal II
查看>>
[LeetCode By Python]108. Convert Sorted Array to Binary Search Tree
查看>>
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode By Python]167. Two Sum II - Input array is sorted
查看>>
[LeetCode BY Python]169. Majority Element
查看>>
[LeetCode By Python]172. Factorial Trailing Zeroes
查看>>