【发布时间】:2019-10-31 03:35:37
【问题描述】:
我有这个代码块 Thymeleaf 调用 Spring 上下文并拉入用户 ID。
<li {#ctx.httpSession} >
<span th:object="${session.user}"> </span>
<span><p>Surname: <span th:text="*{user.id}">Pepper</span></p></span>
我想将它放入现有的 th:replace 列出的项目中。基本上我需要将静态 2 替换为 url 中的当前会话用户 ID,我尝试了许多选项,但似乎无法在线找到解决方案。
This is one of my attempts
<li sec:authorize="isAuthenticated()" {#ctx.httpSession}, th:object="${session.user}" th:replace="::menuItem ( '/users/'+*{user.id}+'/coworkers/find','coworkers','find coworkers','search','Find coworkers')"><span>Find Coworkers</span>
</li>
This is the orginial
<li sec:authorize="isAuthenticated()" th:replace="::menuItem ( '/users/2/coworkers/find','coworkers','find coworkers','search','Find coworkers')">
我是 Thymeleaf 新手,非常感谢任何帮助,谢谢。
已尝试 {*{user.id}}
原因:org.thymeleaf.exceptions.TemplateProcessingException:评估 SpringEL 表达式的异常:“user.id”(模板:“fragments/layout” - 第 65 行,第 106 列)
【问题讨论】: