标签:404错误 ddr try spring end loaded private var com
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);
3.Application.yml里面配置的上传路径
file:
uploadPath: /www/server/*/uploaded_files
路径最后缺少一个/导致附件无法访问 改为
uploadPath: /www/server/*/uploaded_files/
问题解决
springboot上传linux文件无法浏览,提示404错误
标签:404错误 ddr try spring end loaded private var com
原文地址:https://www.cnblogs.com/liw66/p/9987338.html