1. Thymeleaf引用母版页
<!DOCTYPE html>
<!-- 引入对应的命名空间 -->
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
layout:decorator="base/layout3">
<head>
<title>xx</title>
</head>
<body>
<!-- 母版样式 -->
<div layout:fragment="custom_css" >
<link th:href="@{/assets/bootstrap/css/bootstrap-datetimepicker.min.css}" rel="stylesheet"/>
<link th:href="@{/project/css/indicator.css}" rel="stylesheet"/>
</div>
<!-- 引入母版页 -->
<div layout:fragment="page-content" >
<!-- 子页面内容 -->
</div>
2. Spring Boot + Thymeleaf如何直接访问其中的html
如果html文件放到templates里面。项目启动后是不能通过路径访问到,会被拦截了。即ip:port/server-path/templates/xx.html不行
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:templates/
只能自定义Controller跳转到那个视图。内部都封装好了。 想要直接访问可以把他拉到static姿态资源目录下。
3. Themeleaf调用其他静态资源
静态资源一般放在resources/static目录下,如 static/images, static/css, static/js。
引用方法,默认是缺省static文件夹的。如下引用
<link th:href="@{/assets/common/css/layout.css}" rel="stylesheet" />
<!-- ... -->
<div class="text-center">
<img th:src="@{/images/logo.png}" class="rounded" alt="..."/>
</div>
@{/images/logo.png}还不够,对应的HTML标签的属性前面还要加上 th: 命名空间。
不加的话,最原始的路径什么文件夹和相对路径都要考虑进去。很麻烦。
21万+

被折叠的 条评论
为什么被折叠?



