在网上搜索到的大部分解决方案都是[1] 

<a th:href="${#httpServletRequest.getScheme() + '://' + #httpServletRequest.getServerName() + ':' + #request.getServerPort()  + #request.getContextPath() + @{/login}} ">点我啊!</a>

其中:

  • getScheme()获取协议
  • getServerName()获取服务器名
  • getServerPort()服务器端口
  • getContextPath() APP根路径

然而将代码复制修改后的效果是:

前台报错

Thymeleaf 绝对路径

 

 后台报错

Thymeleaf 绝对路径

 

 

org.springframework.expression.spel.SpelParseException: Expression [#httpServletRequest.getScheme() + '://' + #httpServletRequest.getServerName() + ':' + #request.getServerPort()  + #request.getContextPath() + @{/login}] @142: EL1059E: @ or & can only be followed by an identifier or a quoted name

 

 根据报错信息,对方案略微修改:

@{/admin} 修改为 '/admin'

<a th:href="${#httpServletRequest.getScheme() + '://' + #httpServletRequest.getServerName() + ':' + #request.getServerPort()  + #request.getContextPath() + '/admin'}">跳转主页</a>

 

 

 Reference:

[1] sayyy, 【Thymeleaf】获取绝对路径, https://blog.csdn.net/sayyy/article/details/80858392?utm_source=blogkpcl3

 

 

相关文章:

  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-09-21
猜你喜欢
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-02-03
相关资源
相似解决方案