问题描述
限时送ChatGPT账号..我是 Spring MVC 的初学者,我犯了一些错误......所以我想伪造一个带有按钮和 Thymeleaf 的动态 URL,但它不起作用.我想转义引号或类似的, ${key} 在评估中不正确?
i'm a starter in Spring MVC and i make somes mistakes ... so i want to forge a dynamic URL with a button and Thymeleaf, but it doesn't works. I think about escape quote or similar, the ${key} is not correct in the evaluation ?
<tr th:each="key: ${serverBean.getServerB().keySet()}">
<td>
<span th:text="${serverBean.getServerB().get(key)}" />
</td>
<td align="center">
<span th:text="${key}" />
</td>
<td th:if="${protoStatusBean.getStatus(key)}" bgcolor="lime" />
<td th:unless="${protoStatusBean.getStatus(key)}" bgcolor="red"/>
<td>
<button th:onclick="window.location.href='/update?server=${key}'">
<img src="./images/wrench.png" height="15" width="15">
</button>
</td>
</tr>
感谢您的帮助和耐心
推荐答案
通常,您必须用单引号将文本文字括起来.为了让您的示例正常工作,它应该如下所示:
In general, you have to surround text literals with single quotes. For your example to work, it should look like this:
th:onclick="'window.location.href=\'/update?server=' + ${key} + '\''"
话虽如此,根据您认为最好的方式,还有多种其他方法可以使字符串连接工作.
That being said, there are various other ways to get the string concatenation to work, depending on what you think looks best.
th:onclick="|window.location.href='/update?server=${key}'|"
th:onclick="${'window.location.href=''/update?server=' + key + ''''}"
th:onclick="|window.location.href='@{/update(server=${key})}'|"
这篇关于onclick thymeleaf 动态 url 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论