spring mvc 接收所有前端上传文件

    @PostMapping(value = "/upload/file")
    public XXX uploadFile(HttpServletRequest request) throws Exception {
        MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
        Iterator<String> fileNames = multipartHttpServletRequest.getFileNames();
        List<String> nameList = Lists.newArrayList(fileNames);
        log.info("请求的文件名称为:{}", nameList);
for (String s : nameList) {
            List<MultipartFile> files = multipartHttpServletRequest.getFiles(s);
            log.info("请求的文件名称为:{},数量为:{}", s, files.size());
            for (MultipartFile file : files) {
             // 操作
            }
        }
        return XXX;
    }

 

posted @ 2022-06-28 14:38  大哥超帅  阅读(48)  评论(0编辑  收藏  举报