thymeleaf 页面问题(路径,公共模块引入)

路径:href,src

格式: @{  }

eg:   

<link rel="stylesheet" th:href="@{/css/admin.less}" />

<script th:src="@{/js/jquery-3.2.1.min.js}"></script>

一般项目默认static就是根路径,所以static下的路径中不能写static,应当以 / 代替

thymeleaf 创建引入公共模块:

1,th:inssert:保留当前主标签,保留th:fragment主标签;

2,th:replace:舍弃当前主标签,保留th:fragment主标签;

3,th:include:保留当前主标签,舍弃th:fragment主标签。

格式:

引入:<head th:replace="路径 :: 模块名"></head>

模块:<div th:fragment="模块名"></div>

注1:引入的路径以默认的根路径static为相对路径.

eg:  <head th:replace="../templates/system/index/headLink :: links"></head>

注2:引入头部公共外部资源问题

由于<head></head>标签中不能存放<div></div>之类的标签,而不同页面的title基本上都不同,再加上网站后期的SEO优化需要的<meta/>标签,这些都要单独出来

 <head th:replace="路径 :: 模块名"></head>或者

<div th:include="路径 :: 模块名"></div>

都会使引入或者模块中的主标签保留下来

在此处都是不适用的,解决方法如下:

引入:<div th:replace="路径 :: 模块名"></div>

模块:<th:block th:fragment="模块名"></th:block>

<th:block></th:block>是Thymeleaf提供的唯一的一个Thymeleaf块级元素,其特殊性在于Thymeleaf模板引擎在处理<th:block>的时候会删掉它本身,而保留其内容。(多用于渲染平级标签)

th:replace 和<th:block>的结合,完美舍弃引入和模块处的主标签。
---------------------
作者:御神木下的思念
来源:CSDN
原文:https://blog.csdn.net/qq_35123187/article/details/79986039
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/qq_34107571/article/details/85125317