Thymeleaf中的window.location.href

4

我在我的Thymeleaf模板中有一段代码,但它无法正常工作,因为这是生成的位置。

deviceevent/@%7B/deviceevent/list/%7Bid%7D(id=$%7BdeviceEvent.id%7D)%7D

在模板中。
<tr th:each="deviceEvent : ${deviceEvents}"  onclick="window.location.href = '@{/deviceevent/list/{id}(id=${deviceEvent.id})}'" >
1个回答

10

Thymeleaf不会评估属性,除非它们带有th前缀。 在这种情况下,应该使用th:onclick。完整字符串应该是这样的:

th:onclick="'window.location.href = \'' + @{/deviceevent/list/{id}(id=${deviceEvent.id})} + '\''"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接