spring boot 2.0.3 访问静态资源js,css的2种方式
原创    helloworld    发表于:2018-08-21 14:33:22
  阅读 :1.3k+   收藏   编辑

application.properties方式

#静态资源
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static

java方式

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 WebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/")
                //.setCacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic())
                ;
    }
}

老版本继承类WebMvcConfigurerAdapter


评论
条评论