您的位置:首页 > Web前端

spring boot使用thymeleaf模板编写前端程序-文件路径和代码复用

2017-07-18 13:56 381 查看
thymeleaf是一套受spring boot开发者喜爱的前端模板,提供了适合spring boot特有框架体系的特殊html元素,比如html文件引入js代码不需要写绝对路径,只要运用th:src,之后跟templates目录下js文件的路径即可:

<script th:src="@{js/jquery.min.js}" type="text/javascript"></script>

开发文件结构为:



当需要复用html代码时,可以将要服用代码提取到一个html文件中,并使用th:fragment标注想要复用的代码:

<footer th:fragment="footer">
<div class="bloc bgc-white l-bloc">
<div class="container bloc-md">
<div class="row bgc-white">
<div class="col-sm-12 text-center">
<img th:src="@{img/favicon.ico}" class="img-responsive center-block mg-sm" height="38" width="98" />
<p class="text-center">
© FreeCoding-R
</p>
</div>
</div>
</div>
</div>
</footer>

这样,在别的html文件中,便可以通过th:include,指出复用文件的路径以及复用文件中代码段的fragment值来复用这段代码:

<div th:include="components/components :: footer"></div>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐