如何在百里香叶中执行 th:if 语句? [英] How to do a th:if statement in thymeleaf?
问题描述
如何使用 th:if 语句来匹配 2 个表达式?
</表单><!----------------------------------------------------------------------------><tr th:object="${test}"><td th:text ="${test.Status}"></td><td th:text="${test.host}"></td><td th:text="${test.version}"></td></tr>
如何检查 test.host 是否为 = 到 th:field="*host"?这甚至可能吗?
*{host}
与 ${server.host}
相同(因为服务器是你的表单的 th:object).要将其与其他内容进行比较,您可以使用相同的表达式.类似的东西:
th:if="${server.host == test.host}"
这能满足您的需求吗?
<tr th:each="t: ${test}" th:if="${server.host == t.host}"><td th:text="${t.Status}"/><td th:text="${t.host}"/><td th:text="${t.version}"/></tr>
How can I do a th:if statement to match 2 expressions?
<form class="form-horizontal" th:object="${server}" th:action="@{/addServer}" method="POST">
<input type="hidden" th:field="*{id}"/>
<div class="form-group">
<label class="col-sm-2 control-label">Host:</label>
<div class="col-sm-10">
<input type="text" style="width: 500px" class="form-control" th:field="*{host}"/>
</div>
</div>
</form>
<!----------------------------------------------------------------------------->
<tr th:object="${test}">
<td th:text ="${test.Status}"></td>
<td th:text="${test.host}"></td>
<td th:text="${test.version}"></td>
</tr>
How can I check if test.host is = to th:field="*host"? Is this even possible?
*{host}
is the same as ${server.host}
(because server is your form's th:object). To compare it with something else you can use that same expression. Something like:
th:if="${server.host == test.host}"
EDIT: does this do what you want?
<table>
<tr th:each="t: ${test}" th:if="${server.host == t.host}">
<td th:text="${t.Status}" />
<td th:text="${t.host}" />
<td th:text="${t.version}" />
</tr>
</table>
这篇关于如何在百里香叶中执行 th:if 语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!