zoukankan      html  css  js  c++  java
  • Thymeleaf 模板引擎技术

    引入Thymeleaf:

    <!DOCTYPE html>
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <link th:href="@{bootstrap/css/bootstrap.css}" rel="stylesheet"/>
        <link th:href="@{bootstrap/css/bootstrap-theme.css}" rel="stylesheet"/>
        <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
        <title>Index</title>
    </head>
    <body>
    Welcome!
    </body>
    </html>

    引用Web静态资源:

    <link th:href="@{bootstrap/css/bootstrap.css}" rel="stylesheet"/>
    <link th:href="@{bootstrap/css/bootstrap-theme.css}" rel="stylesheet"/>

    访问model(${}):

    <div class="panel-body">
        <span th:text="${person.name}"></span>
        <span th:text="${person.age}"></span>
    </div>

    model迭代访问(th:each指令进行迭代,person为迭代元素,${people}访问people这个model):

    <div class="panel panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title">访问model列表</h3>
        </div>
        <div class="panel-body">
            <ul class="panel-group">
                <li class="list-group-item" th:each="person:${people}">
                    <span th:text="${person.name}"></span>
                    <span th:text="${person.age}"></span>
                </li>
            </ul>
        </div>
    </div>

    数据判断(th:if指令进行判断,支持如 >、< 等类型的比较条件,同时支持SpringEL):

    <div th:if="${not #lists.isEmpty(people)}">内容</div>

    在JavaScript中访问model有些不同,形如 [[${}]]。通过th:inline,才可以访问model):

    <script th:inline="javascript">
        $(function () {
            var person = [[${person}]];
            console.log(person.name + "/" + person.age);
        });
    </script>
  • 相关阅读:
    微信小程序开发教程目录
    Head First设计模式之目录
    CentOS安装NodeJS
    docker镜像打包
    .net core 2.2部署到Windows Server 2012 R2 standard
    MySQL job/定时任务/event 学习
    “sgen.exe”未能运行。文件名或扩展名太长
    Linux 服务器如何设置文件和文件夹的读写权限
    添加“Git Bash Here”到右键菜单
    .Net Core中文编码问题
  • 原文地址:https://www.cnblogs.com/quanxi/p/7264187.html
Copyright © 2011-2022 走看看