springboot~thymeleaf页面布局的步骤

栏目: Java · 发布时间: 5年前

内容简介:参考:https://ultraq.github.io/thymeleaf-layout-dialect/Installation.html注意里面的thymeleaf-layout-dialec就是模板包,必须要安装的,我之前就坑在这里了注意在layout模板里不能再使用其它模板片断了

参考:https://ultraq.github.io/thymeleaf-layout-dialect/Installation.html

依赖包

注意里面的thymeleaf-layout-dialec就是模板包,必须要安装的,我之前就坑在这里了

'org.springframework.boot:spring-boot-starter-thymeleaf',
 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.3.0'

default.html模板页

注意在layout模板里不能再使用其它模板片断了

<!DOCTYPE HTML>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml">
    <head lang="en" th:fragment="head">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

        <link href="../../static/css/bootstrap.min.css"
              th:href="@{/css/bootstrap.min.css}"
              rel="stylesheet" media="screen"/>


        <link href="../../static/css/jquery.dataTables.min.css"
              th:href="@{/css/jquery.dataTables.min.css}"
              rel="stylesheet" media="screen"/>

        <link href="../../static/css/mini_springboot.css"
              th:href="@{/css/mini_springboot.css}"
              rel="stylesheet" media="screen"/>

        <title>SpringBoot</title>
    </head>
    <body>
        <div class="container">
            <div th:fragment="header">
                <nav class="navbar navbar-default">
                    <div class="container-fluid">
                        <div class="navbar-header">
                            <a class="navbar-brand" href="#" th:href="@{/}">Home</a>
                            <ul class="nav navbar-nav">
                                <li>
                                    <a href="#" th:href="@{/init}">初始化</a>
                                </li>
                                <li>
                                    <a href="#" th:href="@{/customers}">客户列表</a>
                                </li>
                                <li>
                                    <a href="#" th:href="@{/customerform}">建立客户</a>
                                </li>
                            </ul>

                        </div>
                    </div>
                </nav>

            </div>

            <div class="panel panel-default">
                <div class="panel-heading">Panel heading without title</div>
                <div class="panel-body">
                    <div layout:fragment="content">content</div>
                </div>
            </div>

            <div th:fragment="footer">

                <div class="footer">大叔直通车:www.lindddd.top</div>


                <script src="../../static/js/jquery.min.js"
                        th:src="@{/js/jquery.min.js}"></script>


                <script src="../../static/js/bootstrap.min.js"
                        th:src="@{/js/bootstrap.min.js}"></script>

                <script src="../../static/js/jquery.dataTables.min.js"
                        th:src="@{/js/jquery.dataTables.min.js}"></script>

                <script src="../../static/js/mini_springboot.js"
                        th:src="@{/js/mini_springboot.js}"></script>

            </div>
        </div>

    </body>
</html>

使用它

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="~{layout/default}">
<head>
    <title>Spring Boot and Thymeleaf - Greeting with Thymeleaf Layout Dialect!</title>
</head>
<body>

<div layout:fragment="content">
    <div th:if="${not #lists.isEmpty(customers)}">
        <table id="customersTable" class="table table-striped">
            <thead>
            <tr>
                <th>Name</th>
                <th>Email</th>
                <th>Age</th>
                <th></th>
            </tr>
            </thead>

            <tbody>
            <tr th:each="customer : ${customers}">
                <td th:text="${customer.id}"></td>
                <td th:text="${customer.name}"></td>
                <td th:text="${customer.email}"></td>
                <td th:text="${customer.age}"></td>
                <td><a th:href="${'/customerdetail/'+customer.id}">查看</a></td>
            </tr>
            </tbody>

        </table>
    </div>
</div>

</body>
</html>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Google将带来什么?

Google将带来什么?

杰夫·贾维斯 / 陈庆新、赵艳峰、胡延平 / 中华工商联合出版社 / 2009-8 / 39.00元

《Google将带来什么?》是一本大胆探索、至关重要的书籍,追寻当今世界最紧迫问题的答案:Google将带来什么?在兼具预言、宣言、思想探险和生存手册性质的这样一《Google将带来什么?》里,互联网监督和博客先锋杰夫·贾维斯对Google这个历史上发展速度最快的公司进行了逆向工程研究,发现了40种直截了当、清晰易懂的管理与生存原则。与此同时,他还向我们阐明了互联网一代的新世界观:尽管它具有挑战性......一起来看看 《Google将带来什么?》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具