js通过 formData传递对象,后台必须有一个对应的实体类接收formData传递过来的值,并且接收的Controller 方法参数不能有注解
1.传递formData的ajax
$.ajax({
url: '/raise_dust/file/insertDeviceVersion',
data: formData,
type: "post",
dataType: "json",
success: function (res) {
layer.msg(res.msg);
if (res.code == 200) {
//操作
layer.close(modal);
}
}
})
2.接受的Controller
@PostMapping(value = "insertDeviceVersion")
@ResponseBody
public JSONObject insertDeviceVersionInformation(FileVersion fileVersion) {
JSONObject jsonObject = new JSONObject();
if (StringUtils.isNotBlank(fileVersion.getVersionName()) && StringUtils.isNotBlank(fileVersion.getVersionId()) //
&& StringUtils.isNotBlank(fileVersion.getVersionTarget()) && StringUtils.isNotBlank(fileVersion.getDownloadAddress())) {
fileService.insertDeviceVersionInformation(fileVersion.getVersionName(), fileVersion.getVersionId(),
fileVersion.getVersionTarget(), fileVersion.getDownloadAddress(), fileVersion.getBriefIntroduction());
jsonObject.put("version", fileVersion.getVersionName());
return jsonObject;
} else {
jsonObject.put("error", "参数信息不能为空!!!");
return jsonObject;
}
}