【问题标题】:get User ID in a Thymeleaf template在 Thymeleaf 模板中获取用户 ID
【发布时间】:2018-11-27 06:54:24
【问题描述】:

我在 Thymeleaf 模板中定义了一个 URL 以连接到需要记录 userId 的 RESTful API,我已经尝试过了,但是检查了模板的源代码,userId 没有被替换

var ajaxUrl = /*[[@{/api/users/@{|~/${#authentication.id}/menus/datatableList}]]*/ "";

【问题讨论】:

  • 应该在<script th:inline="javascript">AFAIR..

标签: jquery spring-mvc spring-boot spring-security thymeleaf


【解决方案1】:

您的 url 表达式应如下所示(您所拥有的没有意义......表达式中的括号和表达式不匹配)。

var ajaxUrl = /*[[@{/api/users/{user}/menus/datatableList(user=${#authentication.id})}]]*/ "";

另外,我什至不确定#authentication.id 是否是#authentication 的有效用法。您是否已验证它实际上包含 id 并且未解析为 null?

【讨论】:

  • 我来自:${#authentication.principal.id}
猜你喜欢
  • 1970-01-01
  • 2014-05-17
  • 2017-09-21
  • 2020-07-05
  • 1970-01-01
  • 2021-04-02
  • 2012-11-22
  • 2014-06-28
相关资源
最近更新 更多