@RequestMapping("/downloadl")
@ApiOperation(value = "下载模版", notes = "下载模版", produces = "application/json; charset=utf-8")
public ResponseEntity<byte[]> downTemplate(HttpServletResponse response, HttpServletRequest request, String excelName, String fileName) throws IOException {
HttpHeaders headers = new HttpHeaders();
fileName="模板";
headers.setContentDispositionFormData("attachment", URLEncoder.encode(fileName, "utf-8") + ".xlsx");
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM)
StringBuffer pathSb = new StringBuffer(ResourceUtils.CLASSPATH_URL_PREFIX);
pathSb.append("template");
pathSb.append(File.separator).append(fileName).append(".xlsx");
File file = ResourceUtils.getFile(pathSb.toString());
InputStream is=new FileInputStream(file);
byte[] byt = new byte[is.available()];
is.read(byt)
return new ResponseEntity<>(byt, headers, HttpStatus.CREATED);
}
服务器不生产文件,客户端直接下载
最新推荐文章于 2021-02-16 11:28:47 发布