springboot+layui样式加载不进来No mapping for GET /layui/css/layui.css

可能是spring boot没有把样式文件扫描进来

@项目目录

springboot+layui样式加载不进来No mapping for GET /layui/css/layui.css_第1张图片

1.第一步:在pojo,controller同级目录下创建config目录,并编写MyConfig代码:

package ecut.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//拓展springmvc
@Configuration
@EnableWebMvc//如果标注了就会被springmvc全面接管
public class MyMvcConfig implements WebMvcConfigurer {

    //样式加载不进来加一句话
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //前端主页控制实现,可以加载样式
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
    }
}

2.如果使用了themlef,记得在pom.xml下导包

 <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-thymeleafartifactId>
        dependency>

3. 前端代码templates/index.html,拿走不谢


<html xmlns:th="http://www.w3.org/1999/xhtml">
<link>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>layout 后台大布局 - Layuititle>
<link th:href="@{/layui/css/layui.css}" rel="stylesheet" href="../static/layui/css/layui.css"/>
head>
<body class="layui-layout-body">
<p th:text="'Hello, ' + ${name} + '!'">3333p>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">layui 后台布局div>
        
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a href="">控制台a>li>
            <li class="layui-nav-item"><a href="">商品管理a>li>
            <li class="layui-nav-item"><a href="">用户a>li>
            <li class="layui-nav-item">
                <a href="javascript:;">其它系统a>
                <dl class="layui-nav-child">
                    <dd><a href="">邮件管理a>dd>
                    <dd><a href="">消息管理a>dd>
                    <dd><a href="">授权管理a>dd>
                dl>
            li>
        ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    贤心
                a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料a>dd>
                    <dd><a href="">安全设置a>dd>
                dl>
            li>
            <li class="layui-nav-item"><a href="">退了a>li>
        ul>
    div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">所有商品a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;">列表一a>dd>
                        <dd><a href="javascript:;">列表二a>dd>
                        <dd><a href="javascript:;">列表三a>dd>
                        <dd><a href="">超链接a>dd>
                    dl>
                li>
                <li class="layui-nav-item">
                    <a href="javascript:;">解决方案a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;">列表一a>dd>
                        <dd><a href="javascript:;">列表二a>dd>
                        <dd><a href="">超链接a>dd>
                    dl>
                li>
                <li class="layui-nav-item"><a href="">云市场a>li>
                <li class="layui-nav-item"><a href="">发布商品a>li>
            ul>
        div>
    div>

    <div class="layui-body">
        
        <div style="padding: 15px;">内容主体区域div>
    div>

    <div class="layui-footer">
        
        © layui.com - 底部固定区域
    div>
div>
<script th:src="@{/layui/layui.js}" src="../static/layui/layui.js">script>
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;

    });
script>
body>
html>

springboot+layui样式加载不进来No mapping for GET /layui/css/layui.css_第2张图片

@前端,http://localhost:8080/,就可以访问

springboot+layui样式加载不进来No mapping for GET /layui/css/layui.css_第3张图片

你可能感兴趣的:(小助手,layui,springboot,样式加载)