簡體   English   中英

Spring 不接受多部分文件列表:java.lang.NoSuchMethodException:org.springframework.web.multipart.MultipartFile

[英]Spring not accepting list of multipart files: java.lang.NoSuchMethodException: org.springframework.web.multipart.MultipartFile

我是通過 AJAX 發送的:

var formData = new FormData();
var totalfiles = document.getElementById('files').files.length;
for (var index = 0; index < totalfiles; index++) {
    formData.append("files", document.getElementById('files').files[index]);
}

而對於我的 Spring 4 應用程序,它應該已經通過這種方法接收了:

@RequestMapping(value = "/mapUploads/submit", method = RequestMethod.POST)
protected void check(HttpServletRequest request, List<MultipartFile> files)

但出於某種原因,Spring 4 告訴我無法實例化 bean:

java.lang.NoSuchMethodException: org.springframework.web.multipart.MultipartFile

在調試模式下,它甚至沒有輸入方法參數。

將方法簽名更改為:

@RequestMapping(value = "/mapUploads/submit", method = RequestMethod.POST)
protected void check(HttpServletRequest request) {
   MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
   List<MultipartFile> files = multipartRequest.getFiles("files");
}

這個問題在這里解決了 但是在那個問題中,OP 只在他的參數中使用了一個 File - 這實際上可以通過在參數簽名中添加MultipartFile來解決:

@RequestMapping(value = "/mapUploads/submit", method = RequestMethod.POST)
protected void check(HttpServletRequest request, MultipartFile>files)

這是我以前的情況,但是當我決定接受文件列表時遇到了 bean 問題。 我決定為那些正在尋找與文件列表相關的解決方案的人創建這個問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM