我将一个formData对象传递给我的Spring后端:
for (int i = 0; i < MAX_MATERIALS; i++)
{
std::string str = "uMaterialProperties[" + std::to_string(i);
g_materialAmbientIndex[i] = glGetUniformLocation( g_shaderProgramID,
(str + "].ambient").data() );
g_materialDiffuseIndex[i] = glGetUniformLocation( g_shaderProgramID,
(str + "].diffuse").data() );
g_materialSpecularIndex[i] = glGetUniformLocation( g_shaderProgramID,
(str + "].specular").data() );
}
控制台日志显示:
imageBanner(banner: File, bannerPath: string, id: number, callback: (response) => void){
var formData = new FormData();
formData.append('name', banner.name);
console.log(formData.get('name'));
formData.append('file', banner);
console.log(formData.get('file'));
this.sendPost("/upload/" + bannerPath, formData, response => {
callback(response);
});
}
所以看起来formData有一些值。
在后端我有这个:
1.jpg
File {name: "1.jpg", lastModified: 1496737372408, lastModifiedDate: Tue Jun 06 2017 10:22:52 GMT+0200 (W. Europe Daylight Time), webkitRelativePath: "", size: 38983…}
我进入控制台的回报是:
&#34; {&#34;时间戳&#34;:1502745177167,&#34;状态&#34;:400,&#34;错误&#34;:&#34;错误请求&#34;,& #34; exception&#34;:&#34; org.springframework.web.bind.MissingServletRequestParameterException&#34;,&#34; message&#34;:&#34;必需的字符串参数&#39; name&#39;不存在&#34;,&#34;路径&#34;:&#34; / beheerback / rest / upload / localeventbanner&#34;}&#34;
它表示名称不存在,但是当我在前端登录时,它会在formData对象中显示名称。
答案 0 :(得分:1)
尝试为名称和文件提供required = false,例如:
@RequestParam(value = "name", required = false, defaultValue = "defaultName") String name, @RequestParam(value = "file" , required = false, defaultValue = "defaultFile") MultipartFile file
然后检查您真正得到的值。另外,在浏览器的开发模式下检查使用网络检查器发送的表单。