파일 배열을 Spring MVC 컨트롤러에 전달하려고합니다. 하지만 400 개의 잘못된 요청 오류가 발생합니다.봄 MVC 컨트롤러에서 jquery를 사용하여 객체 배열 전달
내 jsp에서는 파일 배열을 가져 오기 위해 jquery 메서드를 작성했습니다.
function getFilelist() {
var files = $('body').data('filelist');
return files;
}
그리고 이러한 파일은 모두 Json 방식으로 업로드됩니다. 업데이트
--- ---- 내가 전체의 init() 메소드를 추가하고
:
여기function init() {
$('input:button').button();
$('#submit').button();
$('#uploadForm').submit(function(event) {
event.preventDefault();
alert("uploading..");
$.postJSON('fileSave.htm', {
filename: getFilelist()
},
function(result) {
if (result.success == true) {
dialog('Success', 'Files have been uploaded!');
} else {
dialog('Failure', 'Unable to upload files!');
}
});
});
$('#reset').click(function() {
clearForm();
dialog('Success', 'Fields have been cleared!');
});
$('#upload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result, function (index, file) {
$('body').data('filelist').push(file);
$('#filename').append(formatFileDisplay(file));
$('#attach').empty().append('Add another file');
});
}
});
$("#attach").click(function() {
$("#upload").trigger('click');
});
$('body').data('filelist', new Array());
}
getFilelist은() 파일 객체의 배열입니다. 내 컨트롤러에서 나는 쓴 :
@RequestMapping(value="fileSave", method=RequestMethod.POST)
public @ResponseBody StatusResponse message(
@RequestParam("filesAttachedList") FilesAttachedList filesAttachedList) {
// some code here
}
내 FilesAttachedList
클래스 :
public class FilesAttachedList implements Serializable {
private static final long serialVersionUID = 5944305104394883501L;
private List<FileAttachment> filesList;
public List<FileAttachment> getFilesList() {
return filesList;
}
public void setFilesList(List<FileAttachment> filesList) {
this.filesList = filesList;
}
@Override
public String toString() {
return "FilesAttachedList [filesList=" + filesList + "]";
}
}
그래서 JQuery와에서 객체의 배열을 전달하는 방법은 컨트롤러에? 나는 브라우저를 확인할 때
--updated--
는 getFileList이 내가 두를 추가하면 이미지가
Array[2]
0: Object
1: Object
length: 2
__proto__: Array[0]
개체를 무엇
Object
attachableId: null
attachableType: null
attachmentContentType: null
attachmentFileName: "http://localhost:8080/myproject/resources/images.jpg"
attachmentFileSize: 6994
attachmentUpdatedAt: null
createdAt: null
creatorId: null
id: null
name: "images.jpg"
updatedAt: null
updaterId: null
__proto__: Object
length: 1
__proto__: Array[0]
반환 ---- 업데이트 3 ---
@RequestParam("filesAttachedList") FilesAttachedList filesAttachedList
에서 @RequestBody final String filesAttachedList
으로 변경하고 두 개의 이미지를 추가하면 다음 문자열 객체가 표시됩니다. 이 문자열을 읽을 수 있습니까?
{
"filename": [
{
"id": null,
"createdAt": null,
"updatedAt": null,
"name": "images.jpg",
"attachableId": null,
"attachableType": null,
"attachmentFileName": "http:\/\/localhost:8080\/myproject\/resources\/images.jpg",
"attachmentContentType": null,
"attachmentFileSize": 6994,
"attachmentUpdatedAt": null,
"creatorId": null,
"updaterId": null
},
{
"id": null,
"createdAt": null,
"updatedAt": null,
"name": "lion.jpg",
"attachableId": null,
"attachableType": null,
"attachmentFileName": "http:\/\/localhost:8080\/myproject\/resources\/lion.jpg",
"attachmentContentType": null,
"attachmentFileSize": 36670,
"attachmentUpdatedAt": null,
"creatorId": null,
"updaterId": null
}
]
}
브라우저 디버그에서 데이터 구조 ('getFilelist()'의 결과)를 추가 할 수 있습니까? – Xaerxess
안녕하세요, Xaerxess, 제 질문을 업데이트했습니다. – user965884
안녕하세요, Xaerxess, 다른 사람이 필요하면 알려주세요. – user965884