Spring Boot使用多个对象上传多个文件

时间:2018-12-14 09:50:22

标签: java spring spring-mvc spring-boot postman

我需要帮助,我上次使用一个对象上传单个文件来创建控制器,对我来说就像

我的POJO班

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "file", "data" })
public class FileWithObject<T> {

    @JsonProperty("file")
    private MultipartFile file;
    @JsonRawValue
    @JsonProperty("data")
    private T data;
}
  

我的休息控制器

@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/singleFileUploadWithObject/{folder}",
        method = RequestMethod.POST)
@ResponseBody
// api work
public String singleFileUploadWithObject(
        @PathVariable(name="bucket-uuid", required = true) String bucketUUId,
        @PathVariable(name="folder", required = false) String folder,
        FileWithObject rawData) {
    return pingResponse;
}

我的邮递员结果

enter image description here

这对我来说都是工作。如何通过邮递员发送对象列表,或者可以像下面的REST控制器那样处理请求

@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/listOfObjectsWithSingleFile/{folder}", method = RequestMethod.POST)
@ResponseBody
public String listOfObjectsWithSingleFile(
        @PathVariable(name="bucket-uuid", required = true) String bucketUUId,
        @PathVariable(name="folder", required = false) String folder,
        Set<FileWithObject> rawData) {
    return pingResponse;
}

如何处理对象列表

[{
"file": fileobject,
"data": "zyz"
},{
"file": fileobject,
"data": "zyz"
}]
  

我正在尝试为此打击任务创建api

enter image description here

1 个答案:

答案 0 :(得分:0)


我是通过使用元数据概念完成此操作的,我在 controller and bean

中所做的更改很少
  

控制器

@RequestMapping(value="/filestore/{bucket-uuid}/appsport.com/listOfObjectsWithSingleFile/{folder}",
        method = RequestMethod.POST)
@ResponseBody
public String listOfObjectsWithSingleFile(
        @PathVariable(name="bucket-uuid") String bucketUUId, @PathVariable(name="folder") String folder,
        FileWithObject objects) { // change this Set<FileWithObject> rawData to FileWithObject objects
    return pingResponse;
}
  

Bean

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "file", "files", "data" })
public class FileWithObject<T> {

    @JsonProperty("file")
    private MultipartFile file;
    @JsonProperty("files")
    private List<MultipartFile> files;
    @JsonRawValue
    @JsonProperty("data")
    private T data;

    // work like (meta-data)
    List<FileWithObject> rawData;
    // getter setter
}
  

图像的请求

enter image description here enter image description here

  

注意:-我仍在寻找解决问题的方法

@RequestMapping(value="/filestore/{bucketuuid}/appsport.com/listOfObjectsWithSingleFile/{folder}", method = RequestMethod.POST)
@ResponseBody
public String listOfObjectsWithSingleFile(@PathVariable(name="bucket-uuid", required = true) String bucketUUId,
    @PathVariable(name="folder", required = false) String folder,Set<FileWithObject> rawData) {
    return pingResponse;
}

希望对您有所帮助

相关问题