Thymeleaf 绝对路径


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

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

其中:

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

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

前台报错

 

 后台报错

 

 

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

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM