码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 30.在springboot中使用thymeleaf的模板(include,insert)


    说明:

    本项目是在

    https://blog.csdn.net/weixin_59334478/article/details/126770911?spm=1001.2014.3001.5501icon-default.png?t=M85Bhttps://blog.csdn.net/weixin_59334478/article/details/126770911?spm=1001.2014.3001.5501springboot文章29

    修改而来

    pom.xml文件,核心配置文件等文件,与文章29保持一致,本文只展示最新添加的文件,以减小文章冗余,更容易看出thymeleaf的使用方法。

    知识点:

    1.插入模板相当于,在当前标签中间插入引用过来的模板:例如

    第一种方式使用模板,th:insert

    就等于

    百度公司

    网站:www.baidu.com

    2.包含模板就相当于,引用过来的模板替换了当前的标签,例如:

    就等于

    百度公司

    网站:www.baidu.com

    项目结构:

     

    1.index.html添加连接语句

     

    2.ThymeleafController类添加方法

     

    3.创建html文件

    1)head.html

    1. html>
    2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>headtitle>
    6. head>
    7. <body>
    8. <div th:fragment="top">
    9. <p>百度公司p>
    10. <p>网站:www.baidu.comp>
    11. div>
    12. <div th:fragment="menu">
    13. <p>文档|下载|blogp>
    14. div>
    15. body>
    16. html>

    2)footer.html

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>footertitle>
    6. head>
    7. <body>
    8. <div>
    9. footer.html
    10. @www.baidu.com
    11. div>
    12. body>
    13. html>

    3)common目录下的leaf.html

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>Titletitle>
    6. head>
    7. <body>
    8. <div>
    9. 左侧树形结构
    10. 部门管理
    11. 人员管理
    12. 考勤入口
    13. div>
    14. body>
    15. html>

    4)customtpl.html

    1. html>
    2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>使用模板title>
    6. head>
    7. <body>
    8. <div style="margin-left: 200px;">
    9. <h3>使用其他目录中的模板文件h3>
    10. <div th:insert="common/left :: html">div>
    11. <br/>
    12. <br/>
    13. <div th:include="common/left">div>
    14. <div th:insert="head :: menu">div>
    15. <br/>
    16. <br/>
    17. <h3>插入模板 th:insert 第一种方式h3>
    18. <div th:insert="~{head :: top}">
    19. 第一种方式使用模板,th:insert
    20. div>
    21. <br/>
    22. <br/>
    23. <h3>插入模板 th:insert 第二种方式h3>
    24. <p th:insert="head :: top">p>
    25. <br/>
    26. <br/>
    27. <h3>包含模板, th:include 第一种语法h3>
    28. <div th:include="~{head :: top}">
    29. div>
    30. <br/>
    31. <br/>
    32. <h3>包含模板, th:include 第二种语法h3>
    33. <div th:include="head :: top">
    34. div>
    35. <br/>
    36. <br/>
    37. <h3>使用整个文件作为复用的内容(整个文件作为模板使用)h3>
    38. <div th:include="footer :: html">div>
    39. <br/>
    40. <br/>
    41. <div th:include="footer">div>
    42. <br/>
    43. <br/>
    44. <div th:insert="footer">div>
    45. div>
    46. body>
    47. html>

    4.测试

     

     

  • 相关阅读:
    【算法|前缀和系列No.5】leetcode1314. 矩阵区域和
    DataKit 作为本地获取数据的 API 服务器
    音视频开发:直播推流技术指南
    Python应用爬虫下载QQ音乐歌曲!
    108页6万字某小区施工组织设计方案
    [单片机框架][bsp层][N32G4FR][framework][key_scan] 按键扫描
    无涯教程-Python机器学习 - Stochastic Gradient Boosting函数
    供应链管理(SCM):界面设计全面扫盲,得供应链者得天下
    神奇工具 (支持Android系统)
    Spring Cloud之BootstrapApplicationListener巧妙构建双容器
  • 原文地址:https://blog.csdn.net/weixin_59334478/article/details/126775752
  • 最新文章
  • 【FHE】我们如何实现同态加密推理(八):SiLU 的密文化——两条路径,和一个 8 字节的开关
    SQLcl 中 c/old/new 替换变量为何失效?先定位再替换
    不让模型写作文,直接从它脑子里读答案:Jev 决策在 .NET 的两条路线
    Halo插件:支持GitHub的图床附件策略
    电视投屏界的“一股清流”!SimpleTVCast 6.0.0-beta 抢先体验:无需TV端App,界面大换血!✨
    华三VXLAN集中式网关实战指南:Spine多活网关 + 双活接入(M-LAG)
    软件更好写之后口碑会更重要
    大 O、大 Omega、大 Theta 的区别,O(n) 复杂度是什么意思
    Java标签跳转:一个鲜为人知但却很实用的小技巧
    多智能体系统论文速读
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号