获取参数:<dd th:text="${product.description}"</dd>
格式化价格:<dd th:text="${#numbers.formatDecimal(product.price, 1, 2)}">350.00</dd>
格式化日期:<dd th:text="${#dates.format(product.availableFrom, 'dd-MMM-yyyy')}">28-Jun-2013</dd>
拼字符串:<dd th:text="${'$' + #numbers.formatDecimal(product.price, 1, 2)}">$350.00</dd>
if判断:<span th:if="${product.price lt 100}" class="offer">Special offer!</span>
图片路径:<img th:case="'MALE'" src="../../../images/male.png" th:src="@{/images/male.png}" alt="Male" />
href引用:
<ul>
<li><a href="#" th:href="@{/exercise11/product.html(action='view')}">View product</a></li>
</ul>
each用法:
<tr th:each="product : ${productList}">
<td th:text="${product.description}">Red chair</td>
<td th:text="${'$' + #numbers.formatDecimal(product.price, 1, 2)}">$350</td>
<td th:text="${#dates.format(product.availableFrom, 'dd-MMM-yyyy')}">28-Jun-2013</td>
</tr>
switch用法:
<td th:switch="${customer.gender?.name()}">
<img th:case="'MALE'" src="../../../images/male.png" th:src="@{/images/male.png}" alt="Male" />
<img th:case="'FEMALE'" src="../../../images/female.png" th:src="@{/images/female.png}" alt="Female" />
<span th:case="*">Unknown</span>
</td>
文本框:<textarea id="body" name="body"></textarea>
表单:
<form action="saveCustomer.html" th:action="@{/exercise12/saveCustomer.html}" th:object="${customer}" method="post">
<input type="hidden" th:field="*{id}" />
<label for="firstName">First name:</label>
<input type="text" th:field="*{firstName}" value="John" />
<label for="lastName">Last name:</label>
<input type="text" th:field="*{lastName}" value="Wayne" />
单选框用法:
Genre:
<div th:each="gender : ${genders}" class="radio">
<input type="radio" th:value="${gender}" th:field="*{gender}" />
<label th:for="${#ids.prev('gender')}" th:text="${gender.description}">Male</label>
</div>
<div th:remove="all" class="radio">
<input type="radio" />
<label>Female</label>
</div>
<label for="paymentMethod">Payment method:</label>
<select th:field="*{paymentMethod}" th:remove="all-but-first">
<option th:each="paymentMethod : ${paymentMethods}"
th:value="${paymentMethod}" th:text="${paymentMethod.description}">Credit card</option>
<option>Another payment method</option>
<option>Another payment method</option>
</select>
<label for="balance">Balance (dollars):</label>
<input type="text" th:field="*{balance}" size="10" value="2500" />
<input type="submit" />
格式化价格:<dd th:text="${#numbers.formatDecimal(product.price, 1, 2)}">350.00</dd>
格式化日期:<dd th:text="${#dates.format(product.availableFrom, 'dd-MMM-yyyy')}">28-Jun-2013</dd>
拼字符串:<dd th:text="${'$' + #numbers.formatDecimal(product.price, 1, 2)}">$350.00</dd>
if判断:<span th:if="${product.price lt 100}" class="offer">Special offer!</span>
图片路径:<img th:case="'MALE'" src="../../../images/male.png" th:src="@{/images/male.png}" alt="Male" />
引入js:<script th:src="@{/resources/js/jquery-1.9.1.min.js}"></script>
include:<div th:include="" ></div>
href引用:
<ul>
<li><a href="#" th:href="@{/exercise11/product.html(action='view')}">View product</a></li>
</ul>
each用法:
<tr th:each="product : ${productList}">
<td th:text="${product.description}">Red chair</td>
<td th:text="${'$' + #numbers.formatDecimal(product.price, 1, 2)}">$350</td>
<td th:text="${#dates.format(product.availableFrom, 'dd-MMM-yyyy')}">28-Jun-2013</td>
</tr>
switch用法:
<td th:switch="${customer.gender?.name()}">
<img th:case="'MALE'" src="../../../images/male.png" th:src="@{/images/male.png}" alt="Male" />
<img th:case="'FEMALE'" src="../../../images/female.png" th:src="@{/images/female.png}" alt="Female" />
<span th:case="*">Unknown</span>
</td>
文本框:<textarea id="body" name="body"></textarea>
表单:
<form action="saveCustomer.html" th:action="@{/exercise12/saveCustomer.html}" th:object="${customer}" method="post">
<input type="hidden" th:field="*{id}" />
<label for="firstName">First name:</label>
<input type="text" th:field="*{firstName}" value="John" />
<label for="lastName">Last name:</label>
<input type="text" th:field="*{lastName}" value="Wayne" />
单选框用法:
Genre:
<div th:each="gender : ${genders}" class="radio">
<input type="radio" th:value="${gender}" th:field="*{gender}" />
<label th:for="${#ids.prev('gender')}" th:text="${gender.description}">Male</label>
</div>
<div th:remove="all" class="radio">
<input type="radio" />
<label>Female</label>
</div>
<label for="paymentMethod">Payment method:</label>
<select th:field="*{paymentMethod}" th:remove="all-but-first">
<option th:each="paymentMethod : ${paymentMethods}"
th:value="${paymentMethod}" th:text="${paymentMethod.description}">Credit card</option>
<option>Another payment method</option>
<option>Another payment method</option>
</select>
<label for="balance">Balance (dollars):</label>
<input type="text" th:field="*{balance}" size="10" value="2500" />
<input type="submit" />
</form>
js获取对象:
<script type="text/javascript" th:inline="javascript">
var errorMsg=[[${tpCallBackRes.errorMsg}]];
</script>
官网网址:http://itutorial.thymeleaf.org/
如果你是湖南的 欢迎加入 湖南人在深圳-Java群:557651502