SpringMVC文件上传

导入依赖

 配置appliocationContext-mvc.xml

 FileController

 多文件上传

@RequestMapping("/fileUploads")
    /**
     * MultipartFile 选择的文件
     */
    public String fileUploads(HttpSession session,MultipartFile[] uploadFiles,String author) throws IOException {
        System.out.println("作者:"+author);
        System.out.println(uploadFiles);
        /**
         * 如何处理文件
         */
        for (MultipartFile file:uploadFiles){
            if(!file.isEmpty()){
                //获取文件名称
                String fileName=file.getOriginalFilename();
                //获取到需要上传的路径
                String realPath = session.getServletContext().getRealPath("/WEB-INF/upload");
                //创建文件对象
                File uploadfile=new File(realPath+"\"+fileName);
                //如何上传文件
                file.transferTo(uploadfile);
            }
        }
        return "index";
    }
原文地址:https://www.cnblogs.com/dabrk/p/11836404.html