溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

springboot?themaleaf第一次進頁面不加載css怎么解決

發布時間:2022-10-28 09:26:02 來源:億速云 閱讀:198 作者:iii 欄目:開發技術

今天小編給大家分享一下springboot themaleaf第一次進頁面不加載css怎么解決的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

springboot themaleaf 第一次進頁面不加載css

近期在做springboot +themaleaf項目中遇到首頁css樣式不加載情況,后來發現是注冊攔截器時沒有加入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;
 
/**
 * 配置靜態資源映射
 *
 * @author sunziwen
 * @version 1.0
 * @date 2018-11-16 14:57
 **/
@Component
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     * 添加靜態資源文件,外部可以直接訪問地址
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}

刪除這個類后還是報錯,猜測可能是包路徑問題,重新建立個新項目,將舊項目轉移后,沒有再報錯。

以上就是“springboot themaleaf第一次進頁面不加載css怎么解決”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女