赞
踩
spring:
# 静态资源不拦截,static-path-pattern和static-locations要配合使用
mvc:
# 相当于实现WebMvcConfigurer接口addResourceHandlers方法的registry.addResourceHandler("/**")
static-path-pattern: /**
resources:
# 相当于实现WebMvcConfigurer接口addResourceHandlers方法的registry.addResourceLocations("classpath:/templates/","classpath:/static/")
static-locations: classpath:/templates/,classpath:/static/
import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * 资源拦截器 * @author tyg * @date 2020-09-02 10:26 */ @Configuration public class MyWebMvcConfigurer implements WebMvcConfigurer { /** * 处理静态资源 * @param registry * @author tyg * @date 2020-09-02 10:26 */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { /* * addResourceHandler是访问路径前缀,参数可设置多个,以逗号分隔,例:/image/**,/css/** * addResourceLocations是对应的资源路径,也可以设置多个。 */ registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/"); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。