Thymeleaf 常用属性

获取参数:<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" />


引入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


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值