AJAX 控制器不循环遍历每个文件并保存在位置。只做第一个文件上传

AJAX controller not looping through each file and saving in location. Only doing the first file upload

我下面的代码只是将数组中的第一个文件上传到路径位置。谁能看到我的服务器端控制器出了什么问题:

private static String UPLOADED_FOLDER = "C://temp//";

@RequestMapping(value = { "/fileUpload" }, method = RequestMethod.POST)
@ResponseBody
public String uploadFile( @RequestParam("number") String number, @RequestParam("files[]") MultipartFile[] files, MultipartHttpServletRequest req, HttpServletResponse res)
{       

    for (MultipartFile file : files) {

    try {
        File directory = new File(UPLOADED_FOLDER + number);
        logger.info(directory.toString());
                if (! directory.exists()){
                    directory.mkdir();
                    logger.info("directory created");
                  }
            byte[] bytes = file.getBytes();
            logger.info(bytes.toString());
            Path path = Paths.get(UPLOADED_FOLDER + number + "//" + file.getOriginalFilename());
            logger.info(path.toString());
            Files.write(path, bytes);
            logger.info("You have successfully uploaded '" + file.getOriginalFilename() + "'");
            return("File Uploaded");


    } catch (Exception e) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        logger.error("Failed to upload file '" + file.getOriginalFilename() + "'", e);
        return("File Not Uploaded");
    }
}
    return "redirect:/fileUpload";
}

}
return("File Uploaded");

这打破了循环。

如果你想让它完全运行,你需要在循环结束后放置return