Thymeleaf 引入css js 无效终极解决方案

关于springboot集成thymeleaf后引入css和js无效的问题,下面给出了解决方案,直接上图:

以下是关于静态资源的项目结构

在html代码中引用如代码:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>测试窗口</title>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link th:href="@{/bootstrap/css/bootstrap.css}" href="../static/bootstrap/css/bootstrap.css" rel="stylesheet"/>
    <link th:href="@{/bootstrap/css/bootstrap-theme.css}" href="../static/bootstrap/css/bootstrap-theme.css"
          rel="stylesheet"/>
    <script th:src="@{/script/jquery-3.1.1.min.js}" src="../static/scripts/jquery-3.1.1.min.js"></script>
    <script th:src="@{/bootstrap/js/bootstrap.js}" src="../static/bootstrap/js/bootstrap.js"></script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-4">
            <div class="panel panel-primary">
                <div class="panel-heading text-center">
                    <span class="panel-title">公司信息</span>
                </div>
                <div class="panel-body">
                    公司链接:<span th:text="#{company.url}">www.it.com</span><br/>
                    公司名称:<span th:text="#{company.name}">中国IT控股有限公司</span><br/>
                    公司代码:<span th:text="#{company.code}">00370.hk</span><br/>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

下图为效果图

注:static目录为spring默认静态文件根目录,不需要再yml中特别指出。

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值