zoukankan      html  css  js  c++  java
  • springboot上传linux文件无法浏览,提示404错误

    1.配置文件地址置换
    @Component
    class WebConfigurer implements WebMvcConfigurer {
    @Autowired
    ConfigUtil bootdoConfig;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/files/**").addResourceLocations("file:///"+bootdoConfig.getUploadPath());
    }
    }
    2.配置工具类
    @Component
    @ConfigurationProperties(prefix="file")
    public class ConfigUtil {
    //上传路径
    private String uploadPath;
      public String getUploadPath() {
      return uploadPath;
      }

      public void setUploadPath(String uploadPath) {
      this.uploadPath = uploadPath;
      }
    }
    3.js打开文件地址
    var src = '/files/2018-11-16/*.png';
    $("#viewDiv").empty();
    var obj = $("<iframe src="+src+" width='99%' frameborder='0'></iframe>");
    if(document.documentElement.clientHeight != 0){
    obj.height(document.documentElement.clientHeight)
    }
    $("#viewDiv").append(obj);

    4.Application.yml里面配置的上传路径
    file:
    uploadPath: /www/server/*/uploaded_files

    路径最后缺少一个/导致附件无法访问 改为
     uploadPath: /www/server/*/uploaded_files/

    问题解决


  • 相关阅读:
    JAVA实现图的邻接表以及DFS
    对于JAVA多线程卖票小程序的理解
    我的第一篇博客
    The 'with' and 'as' Keywords
    Buffering Data
    rstrip
    MapFields和并行计算(OpenFOAM)
    Python 调用自己编写的Class
    vs2013和vs2010的配置
    Eclipse的配置
  • 原文地址:https://www.cnblogs.com/liw66/p/9987338.html
Copyright © 2011-2022 走看看