十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这期内容当中小编将会给大家带来有关使用SpringBoot怎么实现一个单文件上传功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

创新互联建站于2013年开始,是专业互联网技术服务公司,拥有项目网站设计、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元芦山做网站,已为上家服务,为芦山各地企业和个人服务,联系电话:18982081108
1. 页面testFile.html
测试文件上传
2. FileController.java
package com.stormkai.controller;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import lombok.extern.slf4j.Slf4j;
@Controller
@RequestMapping("/file")
@Slf4j
public class FileController {
@GetMapping("/index")
public String index() {
return "testFile";
}
@PostMapping("/upload1")
@ResponseBody
public Map upload1(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws IOException {
log.info("系统路径={}",request.getSession().getServletContext().getRealPath(""));
String path = "F:\\uploadfile\\";
if(!new File(path).exists()){
new File(path).mkdirs();
}
file.transferTo(new File(path + file.getOriginalFilename()));
Map result = new HashMap<>();
result.put("status", "true");
result.put("data", null);
return result;
}
} 上述就是小编为大家分享的使用SpringBoot怎么实现一个单文件上传功能了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。