zoukankan      html  css  js  c++  java
  • thymeleaf

    原文链接:https://www.tianmaying.com/tutorial/using-thymeleaf

    模板
    <!DOCTYPE HTML>
    <html xmlns:th="http://www.thymeleaf.org">
    <head>
    <title>hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
    <!--/*@thymesVar id="name" type="java.lang.String"*/-->
    <p th:text="'Hello!, ' + ${name} + '!'" >3333</p>
    </body>
    </html>


    一.

    1.
    <html xmlns:th="http://www.thymeleaf.org">
    总结: 这是使用thymesVar语法的前提

    2.
    <p th:text="'Hello!, ' + ${name} + '!'" >3333</p>
    总结: 获取变量的值:${} 和el一样。但是这个必须放在th:标签里使用

    3.
    <a th:href="@{http://blog.csdn.net/u012706811}">绝对路径</a>
    <a th:href="@{/}">相对路径</a>
    <a th:href="@{css/bootstrap.min.css}">Content路径,默认访问static下的css文件夹</a>

    总结:Thymeleaf对于URL的处理是通过语法@{…}来处理的 类似的标签有:th:href和th:src

    4.字符串替换:
    两种方法:
    (1)<span th:text="'Welcome to our application, ' + ${user.name} + '!'">
    (2)<span th:text="|Welcome to our application, ${user.name}!|">

    总结:这种形式限制比较多,|…|中只能包含变量表达式${…},不能包含其他常量、条件表达式等


    二.

    1.Thymeleaf中使用th:if和th:unless属性进行条件判断

    <a th:href="@{/login}" th:unless=${session.user != null}>Login</a>
    总结: th:unless于th:if恰好相反,只有表达式中的条件不成立,才会显示其内容。

    2.Thymeleaf同样支持多路选择Switch结构:
    <div th:switch="${user.role}">
    <p th:case="'admin'">User is an administrator</p>
    <p th:case="#{roles.manager}">User is a manager</p>
    <p th:case="*">User is some other thing</p>
    </div>


    3.遍历
    <tr th:each="prod : ${prods}">
    <td th:text="${prod.name}">Onions</td>
    <td th:text="${prod.price}">2.41</td>
    <td th:text="${prod.inStock}? #{true} : #{false}">yes</td>
    </tr>

  • 相关阅读:
    thinkphp tp5 常用 functions
    nginx配置虚拟机 vhost 端口号 域名 区分虚拟机
    thinkphp tp5 模板 引擎 字符串 截取 函数 省略 显示
    C++运算符重载
    c++纯虚函数
    c++面向对象模型---c++如何管理类,对象以及它们之间的联系
    c++多态
    c++友元函数
    c语言的函数指针
    c++两种字符串赋值方式 并介绍 C语言下遍历目录文件的方式
  • 原文地址:https://www.cnblogs.com/tian666/p/thymeleaf.html
Copyright © 2011-2022 走看看