温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

springboot themaleaf第一次进页面不加载css如何解决

发布时间:2023-05-19 14:24:09 来源:亿速云 阅读:92 作者:iii 栏目:编程语言

这篇“springboot themaleaf第一次进页面不加载css如何解决”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“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