springboot themaleaf 第一次進(jìn)頁面不加載css的問題
springboot themaleaf 第一次進(jìn)頁面不加載css
近期在做springboot +themaleaf項(xiàng)目中遇到首頁css樣式不加載情況,后來發(fā)現(xiàn)是注冊攔截器時沒有加入css樣式,下邊是最開始代碼
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor( new LoginHandleInterceptor()).addPathPatterns("/**")
.excludePathPatterns("/index.html", // 排除掉首頁請求
"/", // 排除掉首頁請求
) ;
//registry.addInterceptor(new HandlerInterceptor()).
}第一次訪問登錄頁面的時候,對應(yīng)的js css唄攔截器攔截,就沒有加載,只需要把對應(yīng)的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:
調(diào)試時加入了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/");
}
}刪除這個類后還是報錯,猜測可能是包路徑問題,重新建立個新項(xiàng)目,將舊項(xiàng)目轉(zhuǎn)移后,沒有再報錯。
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
idea maven項(xiàng)目無法識別jar包里的class解決方案
這篇文章主要介紹了idea maven項(xiàng)目無法識別jar包里的class解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-06-06
基于java TCP網(wǎng)絡(luò)通信的實(shí)例詳解
本篇文章是對java中TCP網(wǎng)絡(luò)通信的實(shí)例進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
Java 數(shù)組復(fù)制clone方法實(shí)現(xiàn)詳解
這篇文章主要介紹了Java 數(shù)組復(fù)制clone方法實(shí)現(xiàn)詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-11-11
Springboot使用Junit測試沒有插入數(shù)據(jù)的原因
這篇文章主要介紹了Springboot使用Junit測試沒有插入數(shù)據(jù)的原因,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04
Java實(shí)現(xiàn)PDF文件的分割與加密功能
這篇文章主要為大家分享了如何利用Java語言實(shí)現(xiàn)PDF文件的分割與加密以及封面圖的生成,文中的示例代碼簡潔易懂,感興趣的可以了解一下2022-04-04
java存儲以及java對象創(chuàng)建的流程(詳解)
下面小編就為大家?guī)硪黄猨ava存儲以及java對象創(chuàng)建的流程(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-05-05

