jfinal 无法接受FormData()里面的参数

文件上传  form.appdend的参数接收不到,用getPara和getParaMap()都是空。


评论区

doubuxingle

2020-05-26 10:52

https://jfinal.com/doc/3-11

你妹啊

2020-05-26 11:07

@doubuxingle 上传的文件接收到了,额外append的参数,接收不到

你妹啊

2020-05-26 11:08

@你妹啊 用getPara和getParaMap()都是空,浏览器上面可以看到FormData的参数,后台就是接收不到,弄了一上午了,这是bug吗

你妹啊

2020-05-26 11:10

function sub0() {
var formData = new FormData();
formData.append("file",$("#filePath")[0].files[0]);

// var type = $('#file_type').val()
// var user = $('#file_user').val()
formData.append("type","121212")
formData.append("user","112121221")

// console.log(fd.get("type"))
// $("#myFormId").submit();
$.ajax({


// headers: {
// 'Content-Type': 'multipart/form-data'
// },

url: "${base}/business/jsoupProduct/easypoiImport",
data: formData,
type: "POST",
dataType: "formData",
//几个参数需要注意一下
// type: "POST",//方法类型
// dataType: "json",//预期服务器返回的数据类型
[#--url: "${base}/business/jsoupProduct/easypoiImport",--]
[#--data:formData,--]
processData: false,
contentType: false,
// async:true,

beforeSend:function(){
index = layer.load();
},
success: function (result) {
console.log(result);//打印服务端返回的数据(调试用)
if(result.flag){
alert(result.data);
//return true;
//关闭加载层
layer.closeAll('loading');
window.location.reload();
}else {
//"报价失败的商品:"+
alert(result.data);
layer.closeAll('loading');
//return false;
window.location.reload();
}
},
error : function() {
alert("异常!");
}
});

}

后台代码
String type=getPara("type");

Long productCategoryId = getParaToLong("productCategoryId"); //品目

Long brandId = getParaToLong("brandId"); //品牌
String pinpai=getPara("brandId");
Map map1=getParaMap();
UploadFile file = getFile();
File file1 = file.getFile();

久伴轻尘

2020-05-26 11:12

@AuthorityKey("add")
public void uploadImg() {
UploadFile uploadFile = getFile();
if (!FileTool.isImage(uploadFile.getFile())) {
renderResult(SystemStatus.ERROR, "只能上传图片类型");
return ;
}
Attachment attachment = fileService.uploadFile(uploadFile, getPara("busiId"), g
etPara("itemType"),getCurrentUser().getUserId());
renderResult(SystemStatus.SUCCESS, attachment);
}

久伴轻尘

2020-05-26 11:12

我这边一直没有问题,你是不是设置值的方式有问题

久伴轻尘

2020-05-26 11:13

@你妹啊 先获取文件在获取参数

久伴轻尘

2020-05-26 11:14

https://jfinal.com/doc/3-11 注意一下 【特别注意】

你妹啊

2020-05-26 11:34

@久伴轻尘 谢谢指导啊,问题解决了,先获取文件,再获取参数。我之前先获取参数,一直获取不到。谢谢了

热门反馈

扫码入社