SpringBoot上传文件

#设置虚拟目录(application.properties)
spring.resources.static-locations=file:e:\upload

# 单个文件的最大值

 spring.servlet.multipart.max-file-size=1MB
 # 单次请求最大值
 spring.servlet.multipart.max-request-size=10MB

提供上传文件页面

<form method="post" enctype="multipart/form-data"
      action="/springboot-day1/file/upload">
    <input type="file" name="file1">
    <input type="submit" value="上传">
</form>

编写控制器接收要上传的文件

@Controller
@RequestMapping("file")
public class FileController {

    @RequestMapping("upload")
    @ResponseBody
    public String upload(MultipartFile file1) throws IOException {
        file1.transferTo(new File("e:\upload", file1.getOriginalFilename()));
        return "ok";
    }

}
原文地址:https://www.cnblogs.com/huahualove/p/13802709.html