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>

  • 相关阅读:
    CodeForces 745C Hongcow Builds A Nation 并查集
    hdu 1542 Atlantis 矩形面积并
    CodeForces 741C Arpa’s overnight party and Mehrdad’s silent entering
    上海五校联赛 H 调和序列
    C++学习笔记之泛型算法
    hdu 6016 Count the Sheep
    操作系统 银行家算法
    计蒜之道复赛 B D F
    hdu 2966 In case of failure kdtree模板题
    poj 3468 A Simple Problem with Integers 降维线段树
  • 原文地址:https://www.cnblogs.com/tian666/p/thymeleaf.html
Copyright © 2011-2022 走看看