栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

推荐的模板引擎,以减少动态内容的冗余(Spring Boot)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

推荐的模板引擎,以减少动态内容的冗余(Spring Boot)

Use可以使用Thymeleaf Ultraq Layout创建一个基本模板,该模板将充当其他模板的装饰器,如下所示:

base-template.html:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"      xmlns:th="http://www.thymeleaf.org"      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"><head>  <title layout:title-pattern="$CONTENT_TITLE - $LAYOUT_TITLE">Sample</title>  <meta name="description" content=""/>  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>  <!-- all CSS links here --></head><body><div >  <div >    <div layout:fragment="page_content">      <!-- Content from other pages which decorate using this template -->    </div>  </div></div><!-- /.container --><!-- All script tags here --><th:block layout:fragment="scripts">  <!-- If you have any page specific scripts --></th:block></body></html>

然后其他页面将使用上面的模板作为装饰器,如下所示:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"      xmlns:th="http://www.thymeleaf.org"      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"      layout:decorate="~{base-template}"><head>  <title>This page title</title></head><div layout:fragment="page_content">  <!-- content for this page --></div><th:block layout:fragment="scripts">  <!-- add any scripts related to this page --></th:block></html>

语法从

~{base-template}
Thymeleaf 3开始使用。

您可以继续上述方法,而不必在其他页面上重复导航,页眉和页脚。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/635997.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号