springboot+H-ui+thymeleaf頁面出錯

爲什麼我的頁面是這樣的啊?在U-Builder裏面打開是正常的,但是放到項目裏就成了這樣?求大神指點!!!
在這裏插入圖片描述
解決辦法:
添加文件:
在這裏插入圖片描述
文件內容:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *
 */
@Configuration
//@EnableWebSecurity
public class SpringMvcWebConfigSupport implements WebMvcConfigurer{

    /**
     * 默認訪問的是首頁 //保留了SpringBoot的自動配置,也使用了自己的SpringMmv的配置
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");//前拼templates,後拼.html
        registry.addViewController("/index.html").setViewName("index");//瀏覽器發送/請求來到login.html頁面,不用寫controller控制層的請求方法了
    }

    /**
     * 將static下面的js,css文件加載出來
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //registry.addResourceHandler("/static/").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");//路徑需要按照自己的來寫

    }
}

另外還需要注意yml文件中的靜態文件加載路徑有沒有寫對,下圖是·我的,僅供參考:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章