[英]CSS refuses to load with Springboot / Spring Security / Thymeleaf
[英]Thymeleaf + CSS+SpringBoot
我的 CSS 和 Thymeleaf 有問題。
在我的 Spring Boot 應用程序中,我有這樣的結構:
現在,使用名為 ErrorPage 的 html 頁面和名為 Layout.css 的 css 文件,在 ErrorPage 的頭部使用 Thymeleaf:
<link href="../css/Layout.css" th:href="@{css/Layout.css}" type="text/css" />
但這不起作用。
我究竟做錯了什么?
將您的template
文件夾移動到resources
下:
src/main/resource/static/css
(用於 CSS 文件);src/main/resource/templates
(用於 HTML 模板)。 然后按如下方式更正link
標簽:
<link href="../static/css/Layout.css" th:href="@{/css/Layout.css}" rel="stylesheet" />
將您的模板文件夾移動到資源下:
src/main/resources/static/css (for CSS files);
src/main/resources/templates (for HTML templates).
然后按如下方式更正鏈接標簽(相對或絕對):
<link href="../css/firstcss.css" rel="stylesheet">
<link href="/css/secondcss.css" rel="stylesheet">
前面帶有靜態的舊解決方案對我不起作用。
此行為的主要罪魁禍首是自定義安全配置,您很可能在 WebSecurityConfigurerAdapter 子類中執行該配置。 如果您使用 SpringBoot 2+ 版本,則應在 WebSecurityConfigurerAdapter 配置中添加以下行
.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
我有同樣的問題,我的css沒有負載找到!
我將我的CSS移動到文件夾資源/ static / css但它不起作用...
然后檢查我的控制器,我修改了以下內容:
@RequestMapping(value="/{reader}", method=RequestMethod.GET)
// @RequestMapping(value = "/{reader}", method = RequestMethod.GET)
我剛退休方法和值空間......
問候。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.