thymeleaf 获取项目路径 contextPath

thymeleaf 标签:


${#httpServletRequest.getContextPath()}

直接引用 th:οnclick="@{'location.href=\'' + ${#httpServletRequest.getContextPath()} + '/xxxx\'}"


其它:${#servletContext.contextPath} 



javascript中引用

<!-- 根路径 -->
<script type="text/javascript" th:inline="javascript">
   /*<![CDATA[*/
   ctxPath = /*[[@{/}]]*/ '';
   /*]]>*/


console.info(ctxPath);
</script>


版权声明:本文为wdd668原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。