【发布时间】:2020-06-23 07:42:14
【问题描述】:
我想从 Angular 发出 POST 请求,而后端开发人员正在等待这样的 Spring Boot 请求,带有 3 个参数:
@PostMapping(value = "/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> importFile(
@RequestParam(value = "type") Dto dto,
@RequestParam(value = "booleanValue", required = false) Boolean booleanValue,
@RequestParam("file") MultipartFile file)
throws IOException {
在 Angular 方面,我正在尝试构建表单数据,但在编写此代码时无法添加布尔值:
importFile(fileToImport: FileToImport, booleanValue?: boolean) {
const formData = new FormData();
formData.append('type', fileToImport.type);
formData.append('booleanValue', booleanValue);
formData.append('file', fileToImport.file);
return this.http.post('/import', formData);
}
force 出现错误:Argument of type 'boolean' is not assignable to parameter of type 'string | Blob'
那么我怎样才能设置 3 个参数来尊重后端呢?
感谢您的帮助
【问题讨论】:
-
FileToImport类型是什么? -
对不起,我犯了一个错误。这是我的布尔值,我无法添加到我的 formData
标签: angular typescript spring-boot post