在SpringBoot中使用Webjars

1. 引入webjars依賴

在pom.xml文件中引入相關依賴包,例如bootstrap和jQuery:java

<dependencies>
  <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.1.0</version>
    </dependency>

   <dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery</artifactId>
    <version>3.3.1-1</version>
   </dependency>

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>webjars-locator</artifactId>
        <version>0.30</version>
    </dependency>
   </dependencies>

2. 在SpringBoot中添加資源解析

@Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("/webjars/")
                .resourceChain(false)
                .addResolver(new WebJarsResourceResolver())
                .addResolver(new PathResourceResolver());
        super.addResourceHandlers(registry);
    }

便可。jquery

QQ20181101-1.png

相關文章
相關標籤/搜索