首页>代码>spring boot项目通过自定义WebMvcConfigurerAdapter继承类实现访问静态资源文件的实例>/include-javascript-css/src/main/java/com/memorynotfound/thymeleaf/WebConfig.java
package com.memorynotfound.thymeleaf;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(
                "/webjars/**",
                "/img/**",
                "/css/**",
                "/js/**")
                .addResourceLocations(
                        "classpath:/META-INF/resources/webjars/",
                        "classpath:/static/img/",
                        "classpath:/static/css/",
                        "classpath:/static/js/");
    }

}
最近下载更多
最近浏览更多
漫步的海星  LV4 2023年9月26日
skook7  LV2 2023年8月31日
18176866431  LV4 2023年8月28日
微信网友_6449682944987136  LV1 2023年4月26日
张廉彬  LV2 2021年5月31日
Laughingge  LV1 2021年3月19日
linyumalin 2021年2月19日
暂无贡献等级
usernamegs  LV10 2021年1月25日
luoyong12345  LV3 2021年1月9日
一只勤奋的猪猪  LV9 2021年1月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友