• 下载文件(xlsx)


    1. @RequestMapping(value = "/down", method = RequestMethod.GET)
    2. public void down(HttpServletRequest request, HttpServletResponse response) {
    3. DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    4. Resource rs = resourceLoader.getResource(TEMPLETE_FILE);
    5. try {
    6. File file = rs.getFile();
    7. byte[] bytes = new byte[(int) file.length()];
    8. FileInputStream fis = new FileInputStream(file);
    9. fis.read(bytes);
    10. response.setContentType("application/x-download");
    11. response.setHeader("Content-disposition", "attachment;");
    12. OutputStream ouputStream = response.getOutputStream();
    13. ByteArrayOutputStream baos = new ByteArrayOutputStream();
    14. baos.write(bytes, 0, bytes.length);
    15. ouputStream.write(baos.toByteArray());
    16. ouputStream.flush();
    17. ouputStream.close();
    18. fis.close();
    19. } catch (IOException e) {
    20. e.printStackTrace();
    21. }
    22. }
    1. var url = appConfig.baseUrl + "/api/apply/employee/packageStopApply/down";
    2. $http({
    3. method: 'GET',
    4. url: url,
    5. responseType : "blob"
    6. }).success(function (data) {
    7. // 当相应准备就绪时调用
    8. var blob = new Blob([ data ], {type : "applicationvnd.ms-excel"});
    9. var a = document.getElementById("buttonArea");
    10. if (a) {
    11. a.parentNode.removeChild(a);
    12. }
    13. var a = document.createElement("a");
    14. a.id = "downLoadTempleteID";
    15. a.download = "解除劳动关系包.xlsx";
    16. a.href = URL.createObjectURL(blob);
    17. document.body.appendChild(a);
    18. a.click();
    19. angular.element("#spinner").hide();// 关闭蒙板
    20. }).error(function (err) {
    21. debugger
    22. });
    23. }

  • 相关阅读:
    MyBatis学习(二):补充
    字节一面:说说TCP的三次握手
    支付模块实现
    notepad++去除每一行第二个等号之后的内容解决ResolvePackageNotFound
    ps2022 - ps to dxf
    【CSAPP】现代操作系统前几章
    Linux系统编程-文件
    「HarmonyOS」下拉刷新组件使用详情
    解决tomcat时区错误问题
    JDK发布信息、历史及未来规划
  • 原文地址:https://blog.csdn.net/perception952/article/details/133749851