【发布时间】:2019-12-03 18:43:26
【问题描述】:
我正在使用带有角度首页的 Spring Boot 服务器。我有一项服务可以从我的前面下载.xlsx 文件。
这是我的代码: 服务器端代码:
@GetMapping("/ExportExcel{date}")
public ResponseEntity<InputStreamResource> excelExportReport(@RequestParam Date date) throws IOException {
List<InterfaceTable> interfaceTables=interfaceTableRepo.afficheAHT(date);
ByteArrayInputStream in =ExportExcel.ahtToExcel(interfaceTables);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment; filename=customers.xlsx");
return ResponseEntity
.ok()
.headers(headers)
.body(new InputStreamResource(in));
}
角服务:
ExportExcel(date:string){
return this.http.get<Operation[]>(this.exportUrl+date) }
问题是我在角度方面得到了HttpErrorResponse,即使它:
错误:SyntaxError: JSON.parse () 中 JSON.parse () 的位置 0 中的意外标记 P 在 ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:3240:31) 在 Object` 的 XMLHttpRequest.onLoad (http://localhost:4200/vendor.js:9948:51)
【问题讨论】:
标签: angular typescript spring-boot spring-mvc httpclient