ThymeleafTips1.

ThymeleafTips1.

自动加上应用上下文路径

<a th:href="@{/RequestScopeAttribute/servletAPI}">测试SevletAPI向request域添加数据</a>

页面中获取 request 域

<p th:text="${userName}"></p>

页面中获取 session 域

<p th:text="${session.userName}"></p>

页面中获取 application 域

<p th:text="${application.userName}"></p>

for 循环

<tr th:each="user : ${users}">
    <td th:text="${user.userID}"></td>
    <td th:text="${user.name}"></td>
    <td th:text="${user.gender}"></td>
    <td th:text="${user.email}"></td>
    <td th:text="${user.birthDate}"></td>
    <td th:text="${user.age}"></td>
</tr>

表达式拼接

<a class="deleteA" @click="deleteEmployee" th:href="@{'/employee/'+${employee.id}}">delete</a>
<a th:href="@{'/employee/'+${employee.id}}">update</a>
<a class="deleteA" @click="deleteEmployee" th:href="@{/employee/}+${employee.id}">delete</a>
<a th:href="@{'/employee/'+${employee.id}}">update</a>

表单回显

<form th:action="@{/employee}" method="post">
    <input type="hidden" name="_method" value="put">
    <input type="hidden" name="id" th:value="${employee.id}">
    lastName:<input type="text" name="lastName" th:value="${employee.lastName}"><br>
    email:<input type="text" name="email" th:value="${employee.email}"><br>
    <!--
        th:field="${employee.gender}"可用于单选框或复选框的回显
        若单选框的value和employee.gender的值一致,则添加checked="checked"属性
    -->
    gender:<input type="radio" name="gender" value="1" th:field="${employee.gender}">male
    <input type="radio" name="gender" value="0" th:field="${employee.gender}">female<br>
    <input type="submit" value="update"><br>
</form>