Thymeleaf学习

  • th:fragment即代码片段,用于另外的引用
<head th:fragment="common_header(title,links)">
  <title th:replace="${title}">The awesome application</title>

  <!-- Common styles and scripts -->
  <link rel="stylesheet" type="text/css" media="all" th:href="@{/css/awesomeapp.css}">
  <link rel="shortcut icon" th:href="@{/images/favicon.ico}">
  <script type="text/javascript" th:src="@{/sh/scripts/codebase.js}"></script>

  <!--/* Per-page placeholder for additional links */-->
  <th:block th:replace="${links}" />
</head>

具体的使用方法如下:
_header.html:

<header class="navbar-wrapper" th:fragment="public_header">
...
</header>

_index.html:

<head th:replace = "_meta :: public_meta"></head>

th:include比较这个是插入标签内部的内容

  • 这个用于当name没有值时,就输出no user authenticated
span th:text="${user.name} ?: _">no user authenticated</span>
  • 在spring boot 中Thymeleaf一定要依赖下面这个包,不要依赖官网上的包(如果依赖你需要去配置),不然会得到404错误,因为映射不了
<dependency>     
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-thymeleaf</artifactId>
  </dependency>
  • themeleaf类似java中如下循环:
int pageSize = 10;
for(int i = 0; i < pageSize; i++){
}

实现如下

th:each="i : ${#numbers.sequence(0,pageSize)}"
  • js取thymeleaf模板的值
Paste_Image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Thymeleaf简介 前两天学习springboot遇到了thymeleaf,本着不懂就学的原则,网上查资料了解...
    Meditator_6344阅读 6,440评论 0 5
  • Thymeleaf 介绍 Thymeleaf是一种用于Web和独立环境的现代服务器端的Java模板引擎。Thyme...
    鸡毛飞上天吧阅读 1,612评论 0 0
  • thymeleaf介绍 Thymeleaf模板Spring boot 官方推荐使用来代替jsp,是一款用于渲染XM...
    神易风阅读 3,942评论 0 2
  • 1.thymeleaf概念 Thymeleaf是springboot官方推荐方案,用于Web和独立环境的现代服务器...
    lena_b870阅读 3,089评论 0 0
  • Thymeleaf 简介:java模板引擎。能够处理HTML、XML、JAVAScript、Css 甚至纯文本。类...
    Marlon666阅读 3,818评论 1 0

友情链接更多精彩内容