环境:springboot配置
实现功能:自定义配置类,配置指向具体资源路径,即指定的url可访问具体资源
步骤:
- 自定义配置类,继承WebMvcConfigurerAdapter类,重写addResourceHandlers方法
@EnableWebMvc @Configuration public class webConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/templates/**") .addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/templates/"); registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/static/"); super.addResourceHandlers(registry); }
即可通过请求地址:http://localhost:端口号/templates/templates目录下的文件或者多级目录下的文件(如 templates下的目录a的b.jpg文件--------> >> http://localhost:端口号/templates/a/b.jpg) statis也是一样
-
如果要访问某个盘下的文件&#x