zoukankan      html  css  js  c++  java
  • thymeleaf:局部变量 th:with

    局部变量,th:with能定义局部变量:

    <div th:with="firstPer=${persons[0]}">
      <p>
        The name of the first person is <span th:text="${firstPer.name}">Julius Caesar</span>.
      </p>
    </div>

    当th:with被处理,firstPer变量创建一个局部变量和变量添加到map自上下文,

    以便它是用于评估和其他上下文中声明的变量从开始,但只有包含< div >标记的范围内。

    div th:with="firstPer=${persons[0]},secondPer=${persons[1]}">
      <p>
        The name of the first person is <span th:text="${firstPer.name}">Julius Caesar</span>.
      </p>
      <p>
        But the name of the second person is 
        <span th:text="${secondPer.name}">Marcus Antonius</span>.
      </p>
    </div>

    th:width属性允许重用变量定义在相同的属性:

    <div th:with="company=${user.company + ' Co.'},account=${accounts[company]}">...</div>

    例子:

    <div th:switch="${user.role}">
      <p th:case="'admin'">User is an administrator</p>
      <p th:case="#{roles.manager}">User is a manager</p>
    </div>

     默认属性default可以用*表示:

    <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>
  • 相关阅读:
    linux基本命令
    Charles抓包
    html5基础知识
    java流程控制
    Harry Potter and the sorcerer's stone-01 the Boy Who Lived
    java基础知识
    Java程序运行机制
    java基础相关(历史,特性,环境变量)
    markdown基本语法
    Dos相关知识
  • 原文地址:https://www.cnblogs.com/hanxue53/p/7754352.html
Copyright © 2011-2022 走看看