SpringBoot 2.x 静态资源访问方式
新建一个类
- 继承WebMvcConfigurationSupport,对静态资源目录说明
package com.mobai.color.controller;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
}
引用方式(使用了thymeleaf模板引擎)
<link rel="stylesheet" type="text/css" th:href="@{/static/css/bootstrap.min.css}"/>
<link rel="stylesheet" type="text/css" th:href="@{/static/font-awesome/css/font-awesome.min.css}"/>
<link rel="stylesheet" type="text/css" th:href="@{/static/css/style.css}"/>
评论
0 评论