Thymeleaf
Thymeleaf是一种Java模版引擎,“自然模板”是Thymeleaf的一个特色。
穷目楼
白日依山尽,黄河入海流。欲穷千里目,更上一层楼。
展开
-
Thymeleaf属性优先级
同计算机语言中各种操作符有优先级一样,类似的当同一个标签中有多个th:*属性时,Thymleaf在处理这些属性时也有优先级的问题。<ul> <li th:each="item : ${items}" th:text="${item.description}">Item description here...</li></ul>Thymleaf中定义的属性优先级,从上到下优先级越来越低 Or原创 2017-03-09 21:43:48 · 672 阅读 · 0 评论 -
Thymeleaf条件判断
th:ifth:if属性求Bool值,只有true的时候其所在的标签及该标签中的内容才会被渲染到输出结果中<a href="comments.html" th:href="@{/product/comments(prodId=${prod.id})}" th:if="${not #lists.isEmpty(prod.comments)}">view</a>th:if=“express原创 2017-03-12 22:30:08 · 33583 阅读 · 0 评论 -
Thymeleaf中的迭代
Thymleaf中用th:each属性实现迭代操作。 <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} : #{原创 2017-03-16 23:19:31 · 9018 阅读 · 0 评论 -
Thymeleaf中用HTML5语法设置标签和属性
Thymeleaf支持HTML5的 “data-{prefix}-{name}” 语法作为使用th命名空间前缀设置属性的代替。<table> <tr data-th-each="user : ${users}"> <td data-th-text="${user.login}">...</td> <td data-th-text="${user.name}">原创 2017-02-21 21:39:37 · 2534 阅读 · 0 评论 -
Thymeleaf一次性设置多个属性为相同值
Thymeleaf提供了两个特殊的属性用于一次性设置多个属性为相同的值:th:alt-title和th:lang-xmllang。 按名字即可知道 th:alt-title 设置 alt 和title. th:lang-xmllang 设置 lang 和 xml:lang.<img src="../../images/gtvglogo.png" th:attr="src=@{/im原创 2017-02-21 21:37:05 · 1212 阅读 · 0 评论 -
Thymeleaf设置特定属性
Thymeleaf除了有th:attr这种通用的设置属性的方法外,提供了th:*语法设置特定的属性,*为标准属性的属性名。<input type="submit" value="Subscribe me!" th:value="#{subscribe.submit}"/><form action="subscribe.html" th:action="@{/subscribe}"><li><a原创 2017-02-21 21:30:42 · 739 阅读 · 0 评论 -
Thymeleaf设置任意属性
Thymeleaf通过th:attr属性,可以设置任意的html属性。<form action="subscribe.html" th:attr="action=@{/subscribe}"> <fieldset> <input type="text" name="email" /> <input type="submit" value="Subscribe me!" th:at原创 2017-02-21 21:17:54 · 6195 阅读 · 0 评论 -
Thymeleaf的算术操作和比较操作
算术操作Thymeleaf标准表达式引擎支持算术操作符:+, -, *, /(div), %(mod)th:with="isEven=(${prodStat.count} % 2 == 0)"也可以把算术操作符写在变量表达式中th:with="isEven=${prodStat.count % 2 == 0}"此时,表达式的解析实际上是由OGNL/SpringEL完成的比较操作Thymeleaf支持原创 2017-02-16 22:42:02 · 10304 阅读 · 0 评论 -
Thymeleaf条件表达式和默认表达式
条件表达式条件表达式condition?then:else根据conditon的值,只会有then,else中的一个表达式被求值。conditon为true->then, condition为false->else。<tr th:class="${row.even}? 'even' : 'odd'"> ...</tr>其中条件表达式的三个部分`condition?then:else`本身都是表原创 2017-02-16 22:47:55 · 2987 阅读 · 0 评论 -
Thymeleaf设置固定值属性
一些属性的值比较特殊,要么该属性不出现在标签中,要么以固定的内容作为值出现,比如checked,的值只应该是“checked”,其他属性readonly, selected等也有类似的情况。Thymeleaf提供了与这些属性对应的th:*属性,其值作为一个条件被求值,求值如果为true,该属性被设置为对应的固定值,否则该属性将不会被赋值。<input type="checkbox" name="ac原创 2017-02-21 21:34:20 · 1343 阅读 · 0 评论 -
Thymeleaf在属性头部与尾部附加值
Thymeleaf支持在属性的头部和尾部,在原有值的基础上附加新的值,而不仅仅是重新设置整个值。与th:attr对应,有头部附加属性th:attrprepend和尾部附加属性th:attrappend。<input type="button" value="Do it!" class="btn" th:attrappend="class=${' ' + cssStyle}" />当cssStyle为原创 2017-02-21 21:42:18 · 1903 阅读 · 0 评论 -
Thymeleaf的文本操作
th:text属性th:text属性对其属性值求值,然后将求值结果设置为其本身所在标签的body。body> p th:utext="#{home.welcome}">Welcome to our grocery store!p> p>Today is: span th:text="${today}">13 February 2011span>p>body>th:text的原创 2017-02-12 18:02:31 · 4040 阅读 · 0 评论 -
Thymeleaf变量表达式
Thymeleaf的用...来表示变量表达式,正常情况下,执行{...}来表示变量表达式,正常情况下,执行{…}时,实际上是针对context中的variables map执行OGNL表达式。在与SpringMVC集成的时候,用的是Spring EL。<p>Today is: <span th:text="${today}">13 february 2011</span>.</p>实际等效于执行了原创 2017-02-11 21:33:52 · 2051 阅读 · 1 评论 -
Thymeleaf消息表达式
消息表达式用于从消息源中提取消息内容实现国际化。表达式的语法:#{…}<p th:utext="#{home.welcome}">Welcome to our grocery store!</p>消息属性可以是传统的静态值home.welcome=¡Bienvenido a nuestra tienda de comestibles!也可以带有参数声明,参数声明格式符合java.text.Mes原创 2017-02-11 21:41:39 · 5046 阅读 · 1 评论 -
Thymeleaf选择变量表达式
选择变量表达式*{…}是另一种类似...,表示变量的方法,但是选择变量表达式在执行时是在选择的对象上求解,而{...},表示变量的方法,但是选择变量表达式在执行时是在选择的对象上求解,而{…}是在上下文的变量Map上求解。通过th:object属性指明选择变量表达式的求解对象 <div th:object="${session.user}"> <p>Name: <span th:text=原创 2017-02-11 21:46:56 · 3963 阅读 · 3 评论 -
Thymeleaf URL表达式
URL在Thymleaf中是第一类公民,有其专有的表达式语法@{...}。共存在2大类URL:绝对URL http://www.your.domain相对URL,分为四类 相对于页面 user/login.html相对于上下文 /itemdetails?id=3 (服务的上下文名会被自动添加)相对于服务器 ~/billing/processInvoice (可以调用在另一个context(原创 2017-02-12 17:59:07 · 13494 阅读 · 2 评论 -
Thymeleaf字面量
文本字面量用单引号'...'包围的字符串为文字面量,表示单引号本身需要转义\'<p> Now you are looking at a <span th:text="'working web application'">template file</span>.</p>数字字面量所见即所得,0,1,2,3…<p>The year is <span th:text="2013">1492</sp原创 2017-02-12 18:10:58 · 740 阅读 · 0 评论 -
Thymeleaf文本连接和文字替换
文本连接无论是什么形式的文本:字面量'...',变量表达式求值或消息表达式求值的结果,都可以用'+'进行连接th:text="'The name of the user is ' + ${user.name}"文字替换文字替换可以方便的格式化包含变量的字符串,而无需使用文本连接'...' + '...'。文字替换的语法为| text substituion demo ${varialble} |原创 2017-02-12 18:16:39 · 9978 阅读 · 0 评论