springboot themaleaf 第一次進頁面不加載css的問題
springboot themaleaf 第一次進頁面不加載css
近期在做springboot +themaleaf項目中遇到首頁css樣式不加載情況,后來發(fā)現(xiàn)是注冊攔截器時沒有加入css樣式,下邊是最開始代碼
public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor( new LoginHandleInterceptor()).addPathPatterns("/**") .excludePathPatterns("/index.html", // 排除掉首頁請求 "/", // 排除掉首頁請求 ) ; //registry.addInterceptor(new HandlerInterceptor()). }
第一次訪問登錄頁面的時候,對應的js css唄攔截器攔截,就沒有加載,只需要把對應的css,jquery等放入到攔截器中就可以了
public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor( new LoginHandleInterceptor()).addPathPatterns("/**") .excludePathPatterns("/index.html", // 排除掉首頁請求 "/", // 排除掉首頁請求 "/user/login", "/asserts/css/*.css", "/asserts/img/*.svg", "/asserts/js/*.js", "/webjars/bootstrap/4.1.1/css/*.css", "/mancenter/*", "/error", "/asserts/lib/jquery/*","/asserts/lib/*.js") ; //registry.addInterceptor(new HandlerInterceptor()). }
springboot themaleaf 各種報錯問題
1.訪問themaleaf頁面報錯
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.Mon Jun 24 11:08:43 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
錯誤1:
調試時加入了WebMvcConfig類
package com.feilong.Reptile.config; import org.springframework.stereotype.Component; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * 配置靜態(tài)資源映射 * * @author sunziwen * @version 1.0 * @date 2018-11-16 14:57 **/ @Component public class WebMvcConfig implements WebMvcConfigurer { /** * 添加靜態(tài)資源文件,外部可以直接訪問地址 * * @param registry */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); } }
刪除這個類后還是報錯,猜測可能是包路徑問題,重新建立個新項目,將舊項目轉移后,沒有再報錯。
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
詳解Java中的迭代迭代器Iterator與枚舉器Enumeration
Iterator與Enumeration分別是實現(xiàn)迭代器和枚舉器類的接口,下面就帶大家來詳解Java中的迭代迭代器Iterator與枚舉器Enumeration,以及它們之間的區(qū)別.2016-05-05java算法導論之FloydWarshall算法實現(xiàn)代碼
這篇文章主要介紹了算法導論之FloydWarshall算法實現(xiàn)代碼的相關資料,需要的朋友可以參考下2017-05-05Java 遍歷取出Map集合key-value數據的4種方法
這篇文章主要介紹了Java 遍歷取出Map集合key-value數據的4種方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-09-09