Java VUE 使用文件流 实现下载功能

1、后端:controller控制器

 /**
     * 导出 --->资产信息
     * @return
     * @throws IOException
     * @throws DbException
     */
    @RequestMapping(value = "/getExcel2",method = RequestMethod.GET)
    @ResponseBody
    public byte[] aa(HttpServletResponse response){
        byte[] bytes = null;
        try {
            String bmid = "0000000091";
            String bmmc = "服务部";
            List<String> addStatisticalTypeList = new ArrayList<>();
            List<String> reduceStatisticalTypeList = new ArrayList<>();
            List<String> standardList = new ArrayList<>();
           
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            String fileName = URLEncoder.encode("fss.xlsx","utf-8");
            response.setHeader("Content-Disposition","attachment; fileName=\""+fileName+"\"");
            bytes = dcbService.getExcel(bmid,bmmc,standardList,addStatisticalTypeList,reduceStatisticalTypeList);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (DbException e) {
            e.printStackTrace();
        }finally {
            return bytes;
        }
    }

2、前端:

<a :href='${fss}/dcb/getExcel2' >get 流下载</a>

3、浏览器访问: http://localhost:8001/

 

《Java VUE 使用文件流 实现下载功能》

    原文作者:woodFan先生
    原文地址: https://blog.csdn.net/qq_42715494/article/details/97137200
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞