• 模板引擎Thymeleaf 简单笔记


    1、thymeleaf简介

    Thymeleaf is a modern server-side Java template engine for both web and standalone environments, capable of processing HTML, XML, JavaScript, CSS and even plain text.

    现代化、服务端Java模板引擎

    2、基本语法

    1、表达式

    表达式名字

    语法

    用途

    变量取值

    ${...}

    获取请求域、session域、对象等值

    选择变量

    *{...}

    获取上下文对象值

    消息

    #{...}

    获取国际化等值

    链接

    @{...}

    生成链接

    片段表达式

    ~{...}

    jsp:include 作用,引入公共页面片段

     

    2、字面量

    文本值: 'one text' , 'Another one!' ,…数字: 0 , 34 , 3.0 , 12.3 ,…布尔值: true , false

    空值: null

    变量: one,two,.... 变量不能有空格

    3、文本操作

    字符串拼接: +

    变量替换: |The name is ${name}|

    4、数学运算

    运算符: + , - , * , / , %

    5、布尔运算

    运算符: and , or

    一元运算: ! , not

    6、比较运算

    比较: > , < , >= , <= ( gt , lt , ge , le )等式: == , != ( eq , ne )

    7、条件运算

    If-then: (if) ? (then)

    If-then-else: (if) ? (then) : (else)

    Default: (value) ?: (defaultvalue)

    8、特殊操作

    无操作: _

    3、设置属性值-th:attr

    设置单个值

    <form action="subscribe.html" th:attr="action=@{/subscribe}">
      <fieldset>
        <input type="text" name="email" />
        <input type="submit" value="Subscribe!" th:attr="value=#{subscribe.submit}"/>
      </fieldset>
    </form>

    设置多个值

    <img src="../../images/gtvglogo.png"  th:attr="src=@{/images/gtvglogo.png},title=#{logo},alt=#{logo}" />

    以上两个的代替写法 th:xxxx

    <input type="submit" value="Subscribe!" th:value="#{subscribe.submit}"/>
    <form action="subscribe.html" th:action="@{/subscribe}">

    所有h5兼容的标签写法

    https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#setting-value-to-specific-attributes

    4、迭代

    <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>
    <tr th:each="prod,iterStat : ${prods}" th:class="${iterStat.odd}? 'odd'">
      <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>

    5、条件运算

    <a href="comments.html"
    th:href="@{/product/comments(prodId=${prod.id})}"
    th:if="${not #lists.isEmpty(prod.comments)}">view</a>
    <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>

    6、属性优先级

     转载:https://www.yuque.com/atguigu/springboot/vgzmgh

  • 相关阅读:
    HTTPD之五---HTTP协议、相关工具及状态码
    HTTPD之四----实现HTTPD正向代理与反向代理
    第十三周---DNS原理、实现智能DNS及源码编译mariadb数据库
    DNS之五----实现智能DNS
    sqoop 导入增量数据到hive
    Hadoop 二次排序
    Spark foreachpartiton和mappartition的异同
    hadoop 实现多文件输出
    spark 实现多文件输出
    Scala 中 call by name & call by value 的区别
  • 原文地址:https://www.cnblogs.com/LEPENGYANG/p/15603813.html
Copyright © 2020-2023  润新知