【问题标题】:How to set a placeholder into a non-Thymeleaf parameter?如何将占位符设置为非 Thymeleaf 参数?
【发布时间】:2018-12-27 13:32:21
【问题描述】:

我正在尝试在我的 html 页面上实现 SaveToAndroidPay 按钮,该按钮是用 Thymeleaf 创建的。我在 Spring 后端指定的上下文中有一个参数,称为 jwt。

<g:savetoandroidpay jwt="<<<HERE>>>" size="small" theme="light" ></g:savetoandroidpay>

如何将此参数设置为非百里香属性(jwt)? ${jwt} 和 [[${jwt}]] 都不起作用。

【问题讨论】:

  • 我不知道我是否正确,但你可以尝试这样的事情:th:attr="jwt=${#servletContext.getAttribute(jwt)}"
  • @Flocke 它似乎有效!您可以将其发布为答案,我会接受。
  • @Flocke 实际上对我来说只是 th:attr="jwt=${jwt}",没有 servletContext
  • 谢谢,但银河战士的回答比我的要好。

标签: spring spring-mvc thymeleaf android-pay google-pay


【解决方案1】:

在 Thymeleaf 3 中,您可以简单地在属性前面加上 th:。所以:

<g:savetoandroidpay th:jwt="${jwt}" size="small" theme="light" ></g:savetoandroidpay>

如果您使用的是 Thymeleaf 2(这也适用于 Thymeleaf 3),您也可以只使用 th:attr,如评论:

<g:savetoandroidpay th:attr="jtw = ${jwt}" size="small" theme="light" ></g:savetoandroidpay>

【讨论】:

    猜你喜欢
    • 2019-01-03
    • 1970-01-01
    • 2019-09-08
    • 2016-12-15
    • 2012-03-10
    • 1970-01-01
    • 2015-03-13
    • 2020-05-23
    • 1970-01-01
    相关资源
    最近更新 更多