thymeleaf引入公共header

创建公共的header

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:fragment="common_header(title,links,styles)">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" th:href="@{/wms/static/css/bootstrap.min.css}"/>
    <title th:replace="${title}">默认系统名称</title>
</head>
</html>
  • 首先通过html的xmlns属性引入thymeleaf的命名空间。
  • 通过th:fragment标签定义一个模板(值是模板的ID,整个页面唯一),如果是引入整个页面,这个模板标签则不是必须的,它的作用是让其他页面可以包含某个页面的某个代码片段,通过模板ID区分。
  • th:fragment标签值的括号里面的是参数,其他页面包含这个模板的时候可以传递参数过来,然后通过${参数名}格式获取参数值
  • link元素中的th:href也可以传统css样式表引入的方式,两种都可以生效

引入公共header

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/common_header :: common_header(~{::title},~{::link},~{})">
    <title>登录</title>
</head>

htmlhead元素中通过th:replace属性引入,值为模板的路径,不需要模板的后缀后面::跟的是模板的ID(即公共header页面中th:fragment定义的值)。ID后面括号是给模板传递参数,通过~{::元素名}格式能获取指定元素的文本。

转载于:https://www.cnblogs.com/heavenbird/articles/9644985.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值