spring 1.x 上传文件

  1. pom.xml 加入apache的依赖
  2. @Bean
     public MultipartResolver resolver() {
         return new CommonsMultipartResolver();
     }
    
  3. @PostMapping("/uploadFile")
     @ResponseBody
     public Map uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
         String originalFilename = file.getOriginalFilename();
         file.transferTo(new File("d:/" + originalFilename));
         Map map = new HashMap<>();
         map.put("code", 1);
         return map;
     }
    
  4. 上传方法进不去,就是因为没有加那个resolver

你可能感兴趣的:(spring 1.x 上传文件)