springboot上传文件
来源:互联网 发布:文明6mac修改器 编辑:程序博客网 时间:2024/05/01 17:53
springboot上传文件
- springboot上传文件
- 1 Spring Boot 默认使用 springMVC 包装好的解析器进行上传
- 2 代码
- HTML
- controller
- 3 配置
1, Spring Boot 默认使用 springMVC 包装好的解析器进行上传
2, 代码:
HTML
<form method="POST" enctype="multipart/form-data" action="/file/upload"> 文件:<input type="file" name="roncooFile" /> <input type="submit" value="上传" /> </form>
controller
@Controller@RequestMapping(value = "/file")public class FileController { private static final Logger logger = LoggerFactory.getLogger(FileController.class); @RequestMapping(value = "upload") @ResponseBody public String upload(@RequestParam("roncooFile") MultipartFile file) { if (file.isEmpty()) { return "文件为空"; } // 获取文件名 String fileName = file.getOriginalFilename(); logger.info("上传的文件名为:" + fileName); // 获取文件的后缀名 String suffixName = fileName.substring(fileName.lastIndexOf(".")); logger.info("上传的后缀名为:" + suffixName); // 文件上传路径 String filePath = "d:/roncoo/ttt/"; // 解决中文问题,liunx 下中文路径,图片显示问题 // fileName = UUID.randomUUID() + suffixName; File dest = new File(filePath + fileName); // 检测是否存在目录 if (!dest.getParentFile().exists()) { dest.getParentFile().mkdirs(); } try { file.transferTo(dest); return "上传成功"; } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return "上传失败"; }}
3, 配置
#默认支持文件上传.spring.http.multipart.enabled=true #支持文件写入磁盘.spring.http.multipart.file-size-threshold=0 # 上传文件的临时目录spring.http.multipart.location= # 最大支持文件大小spring.http.multipart.max-file-size=1Mb # 最大支持请求大小spring.http.multipart.max-request-size=10Mb
阅读全文
0 0
- SpringBoot文件上传
- springboot文件上传
- SpringBoot上传文件
- springboot 文件上传
- SpringBoot之文件上传
- springboot 文件上传
- SpringBoot实现文件上传
- springboot 上传文件
- Springboot 文件上传
- SpringBoot上传文件
- SpringBoot文件上传控制
- springboot上传文件
- springboot+文件上传和下载
- springboot实现多文件上传
- springboot 文件上传大小配置
- SpringBoot轻松实现文件上传
- 15.springboot实现文件上传
- SpringBoot文件上传和下载
- 中译语通携手合作伙伴 布局俄罗斯大数据市场
- 导购的路上,媒体向左,社区向右
- LBDA第四次理事会议召开 海外年会和共享教育列入2018年重点
- 从0到1,你的导流姿势真的正确吗?
- “融•变” 中译语通助力语言产业未来变革
- springboot上传文件
- Android开发之旅---遇到JsonSyntaxException
- 世界互联网大会:腾讯安全驱动“全时空”安防体系建设 防御信息安全威胁
- 高通正式发布骁龙845芯片,同时还要大举进军笔记本行业
- ios-NSProxy模拟多继承
- Git常用命令
- 揭秘阿迪达斯机器人工厂,是否只是一个昂贵的情怀故事?
- 苹果CEO库克:腾讯是苹果重要的合作伙伴
- Eclipse 调用Win32 C++的dll