springboot加载图片和mp4进行显示的设置类WebMvcConfig

springboot加载图片和mp4进行显示的设置类WebMvcConfig

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

  @Autowired
  private UploadFileProperties uploadFileProperties;


  
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
   registry.addResourceHandler("/file/**").addResourceLocations("file:" + uploadFileProperties.getPath());
  }

}


完成后编译运行就可以通过类似如下方式进行访问
http://192.168.1.103:15061/file/10-23-27.mp4


yml配置文档

upload:
file:
path: D:/ftpfileup #上传文件路径/shuili/ftpfileup D:/ftpfileup
 
UploadFileProperties.java配置类文档
 
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* @Name ConfigurationProperties
*/
@ConfigurationProperties(
prefix = "upload.file"
)
@Component
public class UploadFileProperties {

private String path;

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

}
 

posted on 2022-11-04 09:41  yebinghuai2019  阅读(51)  评论(0编辑  收藏  举报

导航