在我们前端进行表单提交的时候,有时候会出现这种情况:Failed to convert java.lang.String to java.util.List
等等。
例如:
我后台定义一个对象:
examPaper 包含 String userId,Float userScore, MultipartFile examFile 用户id ,试卷分数,试卷文件
对象外面 classPaper有: String classId String className List<examPaper> examPaperList
这个时候,后台接收为 ClassPaper
如果按照平常的 form-data 提交 则应按以下方式提交:
let fd = new FormData();
fd.append("classId ",classId );
fd.append("className ",className );
examPaperList.forEach((item,index) ->{
fd.append("examPaperList["+index+"].userId",item.userId);
fd.append("examPaperList["+index+"].userScore",item.userScore);
fd.append("examPaperList["+index+"].examFile ",item.examFile );
});
以这种方式就可以实现 多附件 一一 对应提交。以避免对象转换错误问题。