springboot-thymeleaf - 内嵌变量和布局

内嵌变量(Utility对象)

使用:"${#对象.方法(参数列表)}"
    dates : java.util.Date 的功能方法类
    numbers : 格式化数字的功能方法
    strings : 字符串对象的功能类
    calendars : 类似#dates,面向java.util.Calendar
    objects: 对objects的功能类操作    
    bools: 对布尔值求值的功能方法
  1. 例.日期格式化(schooltime为后台的Date对象值)
<div th:text="${#dates.format(schooltime,'yyyy-MM-dd HH:mm:ss')}"></div >
  1. 例.字符串拼接
<div th:text="${#strings.append('hello ','world')}"></div>    //打印hello world
  1. 例.使用strings生成随机字符串(2为字符串的长度)
<div th:text="${#strings.randomAlphanumeric(2)}"></div>

thymeleaf - 布局th:include/th:replace

th:include 加载模块的内容,覆盖原标签的内容

th:replace 替换原标签及内容

th:fragment 创建模板。

例子:
页面 hello.html 中th:fragment创建模板
页面 hello2.html 写个div

hello.html
	<div th:fragment="f1"> f1 </div>
	<div th:fragment="f2"> f2 </div>
hello2.html
	<div  style="border: solid 1px red;">hello2页面div</div>

打开两个页面
在这里插入图片描述
分别显示:
在这里插入图片描述
测试th:include

hello2.html
	<div th:include="hello"></div>
	<div th:include="hello::f1" style="border: solid 1px red;">hello2页面div</div>

<!-- hello (指整个hello.html内容) 
	 hello::f (指hello.html中带有 'th:fragment="f1"' 属性的标签及标签内容) -->

注意:访问hello2.html页面使用后台跳转方式

@RequestMapping("/hello")
public String hello(Model model){
    return "hello2";
}

浏览器访问 http://localhost:8080/hello
在这里插入图片描述

测试th:replace

hello2.html
	<div th:include="hello"></div>
	<div th:include="hello::f1" style="border: solid 1px red;">hello2页面div</div>

浏览器访问 http://localhost:8080/hello
在这里插入图片描述


上一章 thymeleaf - 下拉单选多选

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值