onclick thymeleaf 动态 url 参数

编程入门 行业动态 更新时间:2024-10-26 01:34:20
本文介绍了onclick thymeleaf 动态 url 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 14:20:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395729.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   动态   onclick   thymeleaf   url

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!