第一次使用thymeleaf想发送ajax请求但是无法拼出完整的url突然有点不知所措。
问了一下度娘之后终于把这个问题解决了因为很多地方都要用到所以可以截取出来当公共模块。
<!-- thymeleaf模版引擎进行构造完整的url -->
<script
th:fragment="thymeleaf_url" xmlns:th="http://www.springframework.org/schema/mvc" type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
var basePath = /*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/;
/*]]>*/
</script>
我的目录结构是这样的
在哪个页面需要的时候引入就好了
<div th:replace="commons/bar :: thymeleaf_url"></div>
最后
以上就是幸福橘子最近收集整理的关于SpringBoot使用thymeleaf模版引擎构造JavaScript完整的URL的全部内容,更多相关SpringBoot使用thymeleaf模版引擎构造JavaScript完整内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复