MultipartConfig.java 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Copyright 2019 DH
  3. * All right reserved.
  4. * 项目名称: 大恒泰山系统
  5. * 创建日期:2023/10/8
  6. */
  7. package org.springblade.config;
  8. import cn.hutool.core.io.FileUtil;
  9. import org.springframework.beans.factory.annotation.Value;
  10. import org.springframework.boot.web.servlet.MultipartConfigFactory;
  11. import org.springframework.context.annotation.Bean;
  12. import org.springframework.context.annotation.Configuration;
  13. import javax.servlet.MultipartConfigElement;
  14. /***
  15. * Date:2023/10/8
  16. * Title:文件所属模块(必须填写)
  17. * Description:对本文件的详细描述,原则上不能少于30字
  18. * @author dylan
  19. * @version 1.0
  20. * Remark:认为有必要的其他信息
  21. */
  22. @Configuration
  23. public class MultipartConfig {
  24. @Value("${spring.servlet.multipart.location}")
  25. private String tmpLocation;
  26. @Bean
  27. public MultipartConfigElement multipartConfigElement() {
  28. MultipartConfigFactory factory = new MultipartConfigFactory();
  29. System.out.println("******************************* MultipartConfigElement");
  30. // 若没有该目录,则创建,此处使用了第三方插件的FileUtil,各位可以使用原生File实现该逻辑
  31. if (!FileUtil.exist(tmpLocation)) {
  32. FileUtil.mkdir(tmpLocation);
  33. }
  34. factory.setLocation(tmpLocation);
  35. return factory.createMultipartConfig();
  36. }
  37. }