gpt4 book ai didi

Java Spring : Upload multiple MultipartFile files along with JSON as a body into single request(HTTP->POST)?

转载 作者:行者123 更新时间:2023-11-29 07:25:16 27 4
gpt4 key购买 nike

friend 们好,

我正在寻找一种解决方案,我可以上传多个 MultipartFile 连同输入 JSON 正文。我知道有很多相关的东西可用,但我没有找到我的解决方案。这促使我向社区提问。

My requirement is something likewise,

我开发了(事实上正在开发并且处于最后阶段)开源库,学校/学院/大学愿意根据学科知识为学生上传学习 Material 。 连同 Material 用户(经过身份验证)必须提供一些文本信息,例如标题、描述、备注

所以我预期的实体也是类似的东西,

@Entity
class Material {
private MultipartFile[] content;
private String title;
private String description;
private String remarks;
}

我想使用 spring MVC 功能类似的东西哪里失败了,需要你的帮助,

public String uploadMaterial(@RequestBody Material material) {
... business logic ...
return "successfully material saved.";
}

非常感谢任何帮助!!

最佳答案

    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public @ResponseBody Material createMaterial(@RequestPart("addtionalData") String addtionalData, @RequestPart("fileList") List<MultipartFile> fileList) throws IOException {

Material material = new ObjectMapper().readValue(addtionalData, Material.class);
material.setContent(fileList);
// do what ever you want to do
}

关于Java Spring : Upload multiple MultipartFile files along with JSON as a body into single request(HTTP->POST)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54454007/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com