springboot thymeleaf向fragment中传入具体值

现在把html页面中的需要引入的js和css公共部分提取成一个模板,让其他页面在引入这个模板时,只要传入一个当前html的title即可。

模板文件 commonHead.html(存放路径/resources/templates/common/commonHead.html)

<head th:fragment="head(title)">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title th:text="${title}">The awesome application</title>

	<script type="text/javascript" th:src="@{/static/common/js/jquery/1.8.3/jquery-1.8.3.js}"></script>
	<script type="text/javascript" th:src="@{/static/common/js/jquery-impromptu/4.2/jquery-impromptu.4.2.js}"></script>
	
	<link rel="stylesheet" type="text/css" th:href="@{/static/common/css/table.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/static/common/js/jquery-impromptu/4.2/jquery-impromptu.css}"/>
</head>

需要引用模板的网页 test.html

<html>
<head th:include="common/commonHead.html :: head('测试页面')"></head>
<!--或者<head th:include="common/commonHead.html :: head(title='测试页面')"></head>-->
<body>

</body>
</html>

参考链接:

https://blog.csdn.net/whatlookingfor/article/details/78321451

https://github.com/thymeleaf/thymeleaf/issues/350

https://stackoverflow.com/questions/22093149/thymeleaf-fragments-and-default-parameters


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值