【问题标题】:Create a URL based on SpringSecurity username in Thymeleaf在 Thymeleaf 中创建基于 SpringSecurity 用户名的 URL
【发布时间】:2015-09-15 18:27:57
【问题描述】:

使用 Thymeleaf SpringSecurityDialect 我可以像这样显示登录用户的用户名:

Logged in user<span sec:authentication="name">Username</span>

我想更进一步,使用该登录用户名生成 URL。

<a href="view.html" th:href="@{'/view/'+${user.username}}" />

到目前为止,我一直通过将其直接添加到模型中来做到这一点,但是我想知道是否可以仅使用 SecurityDialect 和标签直接做到这一点。

例如,在 JSP 中,将它添加到 pagecontext var 是很简单的。

<sec:authentication var="user" property="principal" />

但是,我想知道是否可以选择在百里香中做类似的事情。

【问题讨论】:

    标签: spring-security thymeleaf


    【解决方案1】:

    您是否尝试过使用 ${#authentication.name} 代替 ${user.username}?它应该工作......

    <a href="view.html" th:href="@{'/view/'+${#authentication.name}}" >TEST</a>
    

    You can find variety of examples here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      • 1970-01-01
      • 2020-04-01
      • 2023-04-03
      • 2015-01-11
      • 2015-04-19
      • 2017-08-16
      相关资源
      最近更新 更多