springboot配置文件中配置路径并引用

199 阅读1分钟
  • 在application.yml中配置本地的文件存储路径(或上传路径):
project:
  imagePath: D:\imagePath
  • 在实现类里面引用路径:
@Value("${project.imagePath}")
private String imagePath;

直接使用即可

  • 拼接路径建议使用File.separator,Windows都可以识别,而Linux只能识别 '/',使用File.separator就不用担心这个问题了
path + File.separator + originalFilename