码农知识堂 - 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.测试

     

     

  • 相关阅读:
    LINQ 查询
    自学(网络安全)黑客——高效学习2024
    ShapeableImageView 的使用,告别shape、三方库
    【天池竞赛】心跳数据挖掘
    宠物医院必备,介绍一款宠物疫苗接种管理软件
    skdaima
    【项目管理】DBClient
    HTML+CSS-Day10
    NOIP2023模拟13联测34 abstract
    路由器二次开发一步一步把工业路由器变成一个高端的可指定出网、节点和链路的路由器,包含详细过程及快捷脚本(二)
  • 原文地址:https://blog.csdn.net/weixin_59334478/article/details/126775752
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号