springboot themaleaf 第一次進(jìn)頁(yè)面不加載css的問(wèn)題
springboot themaleaf 第一次進(jìn)頁(yè)面不加載css
近期在做springboot +themaleaf項(xiàng)目中遇到首頁(yè)css樣式不加載情況,后來(lái)發(fā)現(xiàn)是注冊(cè)攔截器時(shí)沒(méi)有加入css樣式,下邊是最開(kāi)始代碼
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor( new LoginHandleInterceptor()).addPathPatterns("/**")
.excludePathPatterns("/index.html", // 排除掉首頁(yè)請(qǐng)求
"/", // 排除掉首頁(yè)請(qǐng)求
) ;
//registry.addInterceptor(new HandlerInterceptor()).
}第一次訪問(wèn)登錄頁(yè)面的時(shí)候,對(duì)應(yīng)的js css唄攔截器攔截,就沒(méi)有加載,只需要把對(duì)應(yīng)的css,jquery等放入到攔截器中就可以了
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor( new LoginHandleInterceptor()).addPathPatterns("/**")
.excludePathPatterns("/index.html", // 排除掉首頁(yè)請(qǐng)求
"/", // 排除掉首頁(yè)請(qǐng)求
"/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 各種報(bào)錯(cuò)問(wèn)題
1.訪問(wèn)themaleaf頁(yè)面報(bào)錯(cuò)
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
錯(cuò)誤1:
調(diào)試時(shí)加入了WebMvcConfig類(lèi)
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)資源文件,外部可以直接訪問(wèn)地址
*
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
}刪除這個(gè)類(lèi)后還是報(bào)錯(cuò),猜測(cè)可能是包路徑問(wèn)題,重新建立個(gè)新項(xiàng)目,將舊項(xiàng)目轉(zhuǎn)移后,沒(méi)有再報(bào)錯(cuò)。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解Java中的迭代迭代器Iterator與枚舉器Enumeration
Iterator與Enumeration分別是實(shí)現(xiàn)迭代器和枚舉器類(lèi)的接口,下面就帶大家來(lái)詳解Java中的迭代迭代器Iterator與枚舉器Enumeration,以及它們之間的區(qū)別.2016-05-05
java算法導(dǎo)論之FloydWarshall算法實(shí)現(xiàn)代碼
這篇文章主要介紹了算法導(dǎo)論之FloydWarshall算法實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-05-05
Spring Data JPA中的動(dòng)態(tài)查詢(xún)實(shí)例
本篇文章主要介紹了詳解Spring Data JPA中的動(dòng)態(tài)查詢(xún)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04
Java 遍歷取出Map集合key-value數(shù)據(jù)的4種方法
這篇文章主要介紹了Java 遍歷取出Map集合key-value數(shù)據(jù)的4種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
SpringBoot+Vue項(xiàng)目打包部署完整步驟教程
這篇文章主要介紹了SpringBoot+Vue項(xiàng)目打包部署的相關(guān)資料,包括Vue項(xiàng)目的打包設(shè)置、SpringBoot的配置修改、跨域問(wèn)題處理、使用Nginx配置反向代理以及最終的項(xiàng)目啟動(dòng),教程假定開(kāi)發(fā)者已具備完整的前后端分離項(xiàng)目和配置好環(huán)境的服務(wù)器,需要的朋友可以參考下2024-10-10

