简体   繁体   English

通用和通用html thyemleaf数据表页面spring-boot java

[英]common and generic html thyemleaf datatable page spring-boot java

I have more than 300 controllers. 我有300多个控制器。 I would like to have one and only one HTML page for all controllers. 我希望所有控制器只有一个HTML页面。

I know to make loop over a list like this in thyeleaf. 我知道要在thyeleaf中遍历这样的列表。

<tbody>
    <tr th:each="client : ${customerList}">
        <td th:text="${client.getClientID()}"></td>
        <td th:text="${client.getIpAddress()}"></td>
        <td th:text="${client.getDescription()}"></td>
    </tr>
</tbody>

But how to iterate over any list without specifying properties like clientID or ipAddress or description? 但是,如何在不指定诸如clientIDipAddress或description之类的属性的情况下遍历任何列表呢? And be able to do something like this with generic operation: 并能够通过通用操作执行以下操作:

<td><a th:href="'/delete/' + ${client.getClientID}">Delete</a></td>
<td><a th:href="'/edit/' + ${client.getClientID}">Edit</a></td>

hope to be clear 希望清楚

Please see picture . 请看图片

You dont have to specify getClientID() , getIpAddress() at all for just looping through the list. getIpAddress()完全指定getClientID()getIpAddress()即可遍历列表。

<tr th:each="client : ${customerList}">
    <td>Repeat me</td>
</tr>

If you use the above loop you will get <td>Repeat me</td> as many times as the size of the list customerList . 如果您使用上述循环,您会得到<td>Repeat me</td>次数是列表customerList的大小的多少倍。

You can store the data in your model as List<Map<String, String>> where every object of the list is represented as a map , map 's key is object attribute name, and value is object's attribute value. 您可以将数据存储为模型中的List<Map<String, String>> ,其中列表中的每个对象都表示为mapmap的键为对象属性名称, value为对象的属性值。

Then on your view, this will do: 然后在您看来,这将执行以下操作:

<table th:if="${not #lists.isEmpty(listOfMaps)}">
   <thead>
      <!--Columns detection/display -->
      <th th:each="firstObjEntry: ${listOfMaps[0]}" th:text="${firstObjEntry['key']}">
      </th>
   </thead>
   <tbody>
      <tr th:each="objMap: ${listOfMaps}">
         <td th:each="objMapEntry : ${objMap}" th:text="${objMapEntry['value']}"></td>
      </tr>
   </tbody>
</table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM