java - 用百里香添加 css
问题描述
我想访问 login.css 文件。为此,我尝试在登录页面中执行此操作:
<link rel="stylesheet" type="text/css" href="..static/css/login.css" th:href="@{/static/css/login.css}"/>
我有一个 WebConfig:
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
}
}
解决方案
由于您使用 Spring-Boot,因此应自动识别路径。项目结构应该类似:
resources/static/js
resources/static/css
如果没有其他被覆盖的方法,请删除WebConfig
带有注释的类。我建议避免@EnableWebMvc
与 Spring-Boot 一起使用,因为您对 MVC 配置拥有所有控制权(和责任)。
通过以下方式访问静态资源:
<link rel="stylesheet" th:href="@{/css/login.css}"/>
推荐阅读
- html - 最大高度弯曲
- delphi - 在 EXE 和 COM DLL 之间共享对象/接口时的访问冲突
- php - Woocommerce 通过 url 更改产品和数量
- google-cloud-dataprep - 在数据准备中将 YYYY-MM 格式转换为 ShortMonth-YYYY 格式
- javascript - 角度慢视图性能
- tsql - 在选择 ID 后跟 CASE 时限制/聚合结果
- python - 将字典加载到二进制 - 结构格式的坏字符
- php - 在每次对话中获取最新消息
- appium - Appium IOSDriver 超时,但启动 iPhone 模拟器
- c++ - thor::Animator 只播放一帧