thymeleaf里设置路径

栏目: CSS · 发布时间: 7年前

内容简介:版权声明:本文为博主原屙文章,喜欢你就担走。 https://blog.csdn.net/leftfist/article/details/86705844

版权声明:本文为博主原屙文章,喜欢你就担走。 https://blog.csdn.net/leftfist/article/details/86705844

百里香叶子中,设置路径是一个常用的动作。

一、用统一的相对根目录路径来代替页面自己自以为是的相对路径

比如,页面上有路径:

<img src="../images/hi.png" />

这种路径,真正运行起来,不一定正确;即使当时正确,难保以后随着文件夹的变动,变得不正确了。在百里香叶子中,可以用相对根目录的路径来定义:

<!-- 真实路径是 /static/images/hi.png -->
<img th:src="@{/images/hi.png}" />

二、JS中使用相对根目录路径

<script type="text/javascript" th:inline="javascript">

	let configJSON = (/*[[@{/config.json}]]*/'') + '?t=' + new Date().getTime();

</script>

其中, @{/config.json} 就是我们耳熟能详的相对根目录路径,但在JS中,要包在一个类似XML的注释符里:

/*[[@{/config.json}]]*/

如果它还要参与运算,那么还需用大括号括起来:

let configJSON = (/*[[@{/config.json}]]*/'') + '?t=' + new Date().getTime();

三、后台变量是路径的一部分

<link rel="stylesheet" type="text/css" th:href="${pubzy} + '/arcgis_js_api/4.10/esri/css/main.css'" />

后台变量,pubzy。在后台里:

@RequestMapping(value = {"/","/index"}, method = RequestMethod.GET)
    public String getAisBase(Model model) {//返回页面
        model.addAttribute("pubzy", sysConfig.getPubzy());
        return "map/index";
    }

以上所述就是小编给大家介绍的《thymeleaf里设置路径》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

High-Performance Compilers for Parallel Computing

High-Performance Compilers for Parallel Computing

Michael Wolfe / Addison-Wesley / 1995-6-16 / USD 117.40

By the author of the classic 1989 monograph, Optimizing Supercompilers for Supercomputers, this book covers the knowledge and skills necessary to build a competitive, advanced compiler for parallel or......一起来看看 《High-Performance Compilers for Parallel Computing》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具