博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot 文件上传
阅读量:2144 次
发布时间:2019-04-30

本文共 915 字,大约阅读时间需要 3 分钟。

  • SpringBoot上使用文件上传

  1. 编写静态页面,静态页面可以放在classpath/static目录下或者是src/main/webapp目录下及其子目录下都可以

    SpringBoot上传文件
    上传文件:

     

  2. 编写Controller(其中@RestController可以自动把该类下的返回值做json格式转换)

    @RestControllerpublic class FileUpLoadController {		@RequestMapping("/uploadController")	public Map
    fileUpload(MultipartFile multipartFile) throws Exception{ System.out.println(multipartFile.getOriginalFilename()); multipartFile.transferTo(new File("D:/"+multipartFile.getOriginalFilename())); Map
    map = new HashMap<>(); map.put("msg", "OK"); return map; }}

     

  3. 编写启动类

    @SpringBootApplicationpublic class SpringBootFilterApplication {	public static void main(String[] args) {		SpringApplication.run(SpringBootFilterApplication.class, args);	}}

     

  4. 在application.properties文件中设置文件上传的大小(文件上传的默认值)

    spring.http.multipart.maxFileSize=200MBspring.http.multipart.maxRequestSize=200MB

     

转载地址:http://gwegf.baihongyu.com/

你可能感兴趣的文章
【LEETCODE】102-Binary Tree Level Order Traversal
查看>>
【LEETCODE】106-Construct Binary Tree from Inorder and Postorder Traversal
查看>>
【LEETCODE】237-Delete Node in a Linked List
查看>>
【LEETCODE】234-Palindrome Linked List
查看>>
【LEETCODE】217-Contains Duplicate
查看>>
【LEETCODE】310-Minimum Height Trees
查看>>
【LEETCODE】207-Course Schedule
查看>>
【LEETCODE】202-Happy Number
查看>>
和机器学习和计算机视觉相关的数学
查看>>
十个值得一试的开源深度学习框架
查看>>
【LEETCODE】240-Search a 2D Matrix II
查看>>
【LEETCODE】53-Maximum Subarray
查看>>
【LEETCODE】215-Kth Largest Element in an Array
查看>>
【LEETCODE】241-Different Ways to Add Parentheses
查看>>
【LEETCODE】312-Burst Balloons
查看>>
【LEETCODE】232-Implement Queue using Stacks
查看>>
【LEETCODE】225-Implement Stack using Queues
查看>>
【LEETCODE】155-Min Stack
查看>>
【LEETCODE】20-Valid Parentheses
查看>>
【LEETCODE】290-Word Pattern
查看>>