Thymeleaf表演基于条件

时间:2017-03-17 12:39:31

标签: html thymeleaf

我想显示一个只有1个对象不为null,但下面是代码。事实上它是有效的,但我想知道是否有更清洁的方法来做到这一点

Multiple annotations found at this line:
    - Invalid location of tag (div).
    - No end tag (</div>).

模板:

<div  th:if="${currentSkills != null}">
   <tr ><!-- Data File -->
      <td class="col_id">E000</td><!-- ID -->
      <td class="col_name">TD0000 EVB</td><!-- NAME -->
      <td class="col_name">Test Device</td><!-- NAME -->
      <td class="col_battery"><!-- BATTERY -->
    <div class="progressBar" id="max14"><div>
</div></div><!-- bar % (Change ID maxnumber)-->
     </td>
     <td class="col_temp">0ºC / 0ºF </td><!-- TEMP. -->
     <td class="col_last_event">Fri, 17 Mar 2017 10:50:44 GMT+01:00</td><!-- LAST EVENT -->
     <td class="col_signal">149 dBm.</td><!-- SIGNAL -->
     <td class="col_state"></td><!-- STATE -->
    </tr>

1 个答案:

答案 0 :(得分:0)

您可以删除<div>并将th:if直接放在<tr>上来修复所有带注释的错误。

<tr th:if="${currentSkills != null}"><!-- Data File -->
  <td class="col_id">E000</td><!-- ID -->
  <td class="col_name">TD0000 EVB</td><!-- NAME -->
  <td class="col_name">Test Device</td><!-- NAME -->
  <td class="col_battery"><!-- BATTERY -->
    <div class="progressBar" id="max14"><div>
    </div></div><!-- bar % (Change ID maxnumber)-->
  </td>
  <td class="col_temp">0ºC / 0ºF </td><!-- TEMP. -->
  <td class="col_last_event">Fri, 17 Mar 2017 10:50:44 GMT+01:00</td><!-- LAST EVENT -->
  <td class="col_signal">149 dBm.</td><!-- SIGNAL -->
  <td class="col_state"></td><!-- STATE -->
</tr>