gpt4 book ai didi

java - Spring Controller 获取空对象

转载 作者:行者123 更新时间:2023-11-30 02:40:21 28 4
gpt4 key购买 nike

我通过 jsp 表单向 spring Controller 发送一个对象。

JSP:

<form:form modelAttribute="uploadItem" action="/uploadObject" method="post" enctype="multipart/form-data">

<form:input path="fileData" accept="audio/mpeg" type="file" id="file-upload" name="file-upload" />

<form:input type="text" path="title" id="upload-title" name="upload-title"/>

<input type="image" src="..." alt="Upload"/>

</form:form>

模型服务:

 public void fillUploadMelodyModel(Model model) {
fillAdminRootModel(model);
model.addAttribute("uploadItem", new UploadedItem());
}

上传的项目:

public class UploadedItem {
private CommonsMultipartFile fileData;
private String title;
}

Controller :

 @RequestMapping(value = "/uploadObject", method = RequestMethod.POST)
public String doUpload(UploadedItem uploadItem, BindingResult result, Principal principal) {
//at this point I get an empty object (null null values)
}

有什么问题吗?如何在jsp中将对象传递给 Controller ​​?

最佳答案

尝试像这样更改你的 Controller

@RequestMapping(value = "/uploadObject", method = RequestMethod.POST)
public String doUpload(UploadedItem uploadItem,
BindingResult result,
@RequestParam("fileData") MultipartFile file,
@RequestParam("title") String title,
Principal principal) {
//Here you should receive your parameters
}

关于java - Spring Controller 获取空对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41937996/

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