如何在百里香叶中执行 th:if 语句? [英] How to do a th:if statement in thymeleaf?

查看:44
本文介绍了如何在百里香叶中执行 th:if 语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 th:if 语句来匹配 2 个表达式?

 
<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}"/>

</表单><!----------------------------------------------------------------------------><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屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆