java在表单组内部发布多部分(文件)
和title一样,我使用Angular 11/Java时,在将代码发布到服务器时遇到问题,服务器请求在主体中使用多部分类 这是我的密码:
正文(服务器请求):
@Getter
@Setter
@RequiredArgsConstructor
public class FooVM implements Serializable {
...
@Schema(description = "Name of foo.", example = "NAME", required = true)
private String name;
@Schema(description = "image of foo.", example = Constants.Api.FieldExample.FILE,
required = true)
private Multipart file;
控制器(服务器):
@PostMapping(value = /add)
public ApiResponseEntity add(@RequestBody FooVM fooVM) throws IOException {
FooDTO fooDTO = convertVMToDto(fooVM);
if (!validateFoo(fooDTO)) throw new Exception(....);
boolean result = fooService.create(fooDTO );
if (!result) throw new Exception(....);
return ApiResponseEntity.bodyOk().build();
}
机构(客户):
...
name: string;
imageUrl: File;
我在尝试发布时遇到以下错误:
org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class org.springframework.web.multipart.MultipartFile]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
org.springframework.web.multipart.MultipartFile
(no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information at [Source: (PushbackInputStream); line: 1, column: 167] (through reference chain: io.fooBar.api.vm.fooVM["file"])
- 我怎样才能解决这个问题,这个问题可以解决吗李>
注意:我已经配置了内容类型:多部分/表单数据,但仍然没有帮助
共 (0) 个答案