使用Java Spring MVC + Thymeleaf更新网页元素而无需刷新

问题描述

我正在构建一个Web应用程序,该应用程序通过COAP协议监视一系列传感器节点和执行器的状态。当我获得新的读数(例如温度变化)时,我想更新网页上的相应数据。

在网页上,我有一张表,其中包含所有节点的信息,每行一个节点。 理想情况下,我想“获取”相应节点的表行,并使用新的表行更改温度值。

我找不到在Spring控制器中执行此操作的方法。

这是HTML Thymeleaf表:

<table style="display: inline-block" id="actuatorTable" border="1px solid black">
    <thead style="font-weight:bold;">
    <tr>
        <th>NAME</th>
        <th>IP</th>
        <th>TYPE</th>
        <th>RESOURCE</th>
        <th>VALUE</th>
        <th></th>
    </tr>
    </thead>
    <tbody>
    <tr th:each="actuator: ${actuators}">
        <td th:utext="${actuator.nodeName}"></td>
        <td th:utext="${actuator.nodeIP}"></td>
        <td th:utext="${actuator.nodeType}"></td>
        <td th:utext="${actuator.nodeResource}"></td>
        <td th:utext="${actuator.currentValue}"></td>
        <td><button th:nodeIP="${actuator.nodeIP}" onclick="changeStatus(this.getAttribute('nodeIP'),'on')">ON</button></td>
        <td><button th:nodeIP="${actuator.nodeIP}" onclick="changeStatus(this.getAttribute('nodeIP'),'off')">OFF</button></td>
    </tr>
    </tbody>
</table>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)