解决方案:使用系统属性(如System.getProperty("os.name"))来动态选择适合当前操作系统的路径格式。例如,使用file:前缀在Windows和Linux上都是有效的,但你可能需要处理路径分隔符(\ vs /)的差异。通过以上步骤和注意事项,你应该能够成功地在Spring Boot或Spring MVC项目中配置静态资源的访问路径。
FilePathConfig中的代码 @ConfigurationpublicclassFilePathConfig extends WebMvcConfigurerAdapter { @OverridepublicvoidaddResourceHandlers(ResourceHandlerRegistry registry) {//和页面有关的静态目录都放在项目的static目录下registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");//regist...
("file:G:/itemsource/smallapple/")//媒体资源.addResourceLocations("classpath:/META-INF/resources/");//swagger2页面}else{//linux 和macregistry.addResourceHandler("/smallapple/**") .addResourceLocations("file:/resources/smallapple/")//媒体资源.addResourceLocations("classpath:/META-INF/resources/")...
第一步: 配置配置文件填加 classpath:/image/ 第二步:映射请求到图片路径下registry.addResourceHandler("/image/**").addResourceLocations("file:" + SystemAPI.filePath); 注意:SystemAPI.filePath为要访问的文件夹路径整体代码如图 03-springboot静态资源访问规则 ...
this.registration.addResourceLocations("[charset=ISO-8859-1]file:///tmp"); this.registration.resourceChain(true); ResourceHttpRequestHandlerhandler=getHandler("/resources/**"); UrlResourceresource=(UrlResource)handler.getLocations().get(1);