SpringBoot返回文件

public ResponseEntity exportSiteList(@RequestParam("task_id") Integer task_id){
       

//业务逻辑
........


        List> data = new ArrayList(); //即将导出数据集合
        for(PlatformDataAnnotationVerify obj: records){
           
        String path="";
        try {
            path = getClass().getResource("/").toURI().getPath();
            path=path.substring(0,path.length()-16);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        String filename= ExportExcel.exportExcel(heads, data, path);
        FileSystemResource fileResource = new FileSystemResource(filename);
        ResponseEntity responseEntity = ResponseEntity
                .ok()
                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileResource.getFilename() + "\"")
                .body(fileResource);
        return responseEntity;

    }

你可能感兴趣的:(spring,boot,java,后端)