spring boot 输出流文件下载

 
 public void downloadProductInterface(@Valid DownloadProductInterfaceDTO interfaceDTO,
                                         @SuppressWarnings("unused") BindingResult bindingResult, HttpServletResponse response) throws IOException {


        log.debug("name is {}, library is {}", interfaceDTO.getName(), interfaceDTO.getLibrary());
        @SuppressWarnings("unchecked")
        Map map = BeanToMapUtils.toMap(interfaceDTO);
        ServiceReturn serviceReturn = dataProductService.find(map);
        response.setHeader("Content-Disposition", "attachment; filename=" + serviceReturn.getBody().getLibrary() +
                "_" + serviceReturn.getBody().getName() + ".json");
        Integer contentLength = serviceReturn.getBody().getData().getBytes().length;
        response.setHeader("content-length", contentLength + "");
        response.getOutputStream().write(serviceReturn.getBody().getData().getBytes());

    }

 

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