SpringBoot1.5.x 集成Thymeleaf2.1.x 使用公共页面,提示如下错误信息:
Error resolving template [/common/head], template might not exist or might not be accessible by any
thymeleaf 需要注意配置:
# 访问template下的html文件需要配置模板,映射
spring.thymeleaf.prefix.classpath=/templates
thymeleaf 报错写法:
<head th:replace="~{common/head}">
<meta charset="UTF-8"/>
<title>图书管理系统</title>
<link rel="stylesheet" href="../static/css/bootstrap.min.css"/>
<script src="../static/js/jquery-3.3.1.min.js" ></script>
<script src="../static/js/popper.min.js" ></script>
<script src="../static/js/bootstrap.min.js"></script>
</head>
thymeleaf 正确写法:
<!doctype html>
<html lang="en">
<head th:replace="common/head::head">
<meta charset="UTF-8"/>
<title>图书管理系统</title>
<link rel="stylesheet" href="../static/css/bootstrap.min.css"/>
<script src="../static/js/jquery-3.3.1.min.js" ></script>
<script src="../static/js/popper.min.js" ></script>
<script src="../static/js/bootstrap.min.js"></script>
</head>