最近在学习spring实战这本书时,使用thymeleaf模板引擎时,用到了th:object标签。在查询thymeleaf官方文档后,得到了一些相关的内容。

以下是文档中的一段话:

Not only can variable expressions be written as ${…} , but also as *{…} . There is an important difference though: the asterisk syntax evaluates expressions on selected objects rather than on the whole context. That is, as long as there is no selected object, the dollar
and the asterisk syntaxes do exactly the same.
And what is a selected object? The result of an expression using the th:object attribute.
Let’s use one in our user profile ( userprofile.html ) page:

翻译:变量表达式不仅可以写成${…},还可以写成*{…}。但有一个重要的区别:星号语法计算选定对象上的表达式,而不是对整个上下文。也就是说,只要没有选定的对象,美元和星号的语法就完全相同。

th:object表示替换对象, 在一个标签里使用th:object="xxx"时,可以在其子标签里使用*{…}来获取xxx里面的属性。

<div th:object="${session.user}"> <!-- 给这个div标签选定一个object:user-->
<!-- 使用*{...}可以选取user的某个属性--><p>Name: <span th:text="*{firstName}">Sebastian</span>.</p> <p>Surname: <span th:text="*{lastName}">Pepper</span>.</p><p>Nationality: <span th:text="*{nationality}">Saturn</span>.</p> </div>

但如果没有th:object时,*{}作用就相当于${}:

<div> <p>Name: <span th:text="*{session.user.name}">Sebastian</span>.</p><p>Surname: <span th:text="${session.user.surname}">Pepper</span>.</p> <p>Nationality: <span th:text="*{session.user.nationality}">Saturn</span>.</p>
</div>

thymelea的th:object相关推荐

  1. 在kotlin companion object中读取Bean,注入Bean对象

    在kotlin companion object中读取Bean,注入Bean对象 在使用kotlin时,或多或少地会使用到一些公共组件,如 http. mongo. redis相关的组件.   使用组 ...

  2. 在kotlin companion object中读取spring boot配置文件,静态类使用@Value注解配置

    在kotlin companion object中读取配置文件 静态类使用@Value注解配置 class Config {@Value("\${name}")fun setNam ...

  3. Object的finalize()方法的作用是否与C++的析构函数作用相同

    Object的finalize()方法的作用是否与C++的析构函数作用相同 public class Finalization {private static Finalization finaliz ...

  4. libgstreamer-1.0.so.0: cannot open shared object file: No such file or directory

    1. 问题现象 error while loading shared libraries: libgstreamer-1.0.so.0: cannot open shared object file: ...

  5. RuntimeError: Expected object of backend CUDA but got backend CPU for argument

    RuntimeError: Expected object of backend CUDA but got backend CPU for argument #4 'mat1' 原因:变量没有加cud ...

  6. RuntimeError: Expected object of device type cuda but got device type cpu for argument pytorch数据位置

    RuntimeError: Expected object of device type cuda but got device type cpu for argument #2 'target' i ...

  7. Python错误:AttributeError: 'generator' object has no attribute 'next'解决办法

    今天在学习生成器对象(generation object)运行以下代码时,遇到了一个错误: #定义生成器函数 def liebiao(): for x in range(10): yield x #函 ...

  8. Java OOP(Object Oriented Programming)个人理解及总结

    面向对象编程(Object Oriented Programming,OOP,面向对象程序设计) 其三大特征:封装,继承,多态: 封装:解决数据的安全问题. 继承:解决代码的重用问题. 多态:解决程序 ...

  9. 目标检测数据集The Object Detection Dataset

    目标检测数据集The Object Detection Dataset 在目标检测领域,没有像MNIST或Fashion MNIST这样的小数据集.为了快速测试模型,我们将组装一个小数据集.首先,我们 ...

最新文章

  1. Bochs调试Linux内核6 - 启动过程调试 - 跳到bootsect引导程序执行
  2. 【数据结构】ArrayList原理及实现学习总结
  3. 最优化课堂笔记03:整数规划
  4. JavaScript权威指南(第5版)pdf
  5. redis事务的简单介绍
  6. 程序员的大学|彪悍的人生可以没有妹,但必须要有技术!
  7. ceph怎么搭建文件存储_SUSE专家谈Ceph落地之最佳实践
  8. windows10怎样关闭,开机启动项中不需要的应用?
  9. oracle创建登录用户有限制吗,Oracle创建用户限制文件,表空间用户授权等。
  10. FZU 1054 阅读顺序
  11. macOS Monterey 12.0.1(21A559) 正式版三分区原版黑苹果镜像
  12. 三丈红尘,八千里风月
  13. 浏览器劫持事件处置(麻辣香锅)
  14. python 列表嵌套字典 添加修改删除_python3--字典,字典的嵌套,概念:分别赋值
  15. 阿里和CVTE秋招面试题
  16. php 根据日期获取星座,js 根据日期获取星座名称
  17. 如何在Anaconda创建新环境
  18. 【Java杂货铺】JVM#Java高墙之内存模型
  19. windows核心编程 第四章 进程
  20. 【数据挖掘之关联规则实战】关联规则智能推荐算法

热门文章

  1. linux jdk1.8 64位下载永久地址,ubuntu,centos,java
  2. 常用快递电子面单api接口及对接调用方式
  3. 删除ATI催化剂控制中心桌面右键菜单
  4. 智能汽车“三国杀”,哪种模式即将突围?
  5. 【Oracle数据库丢失表排查思路】
  6. 基于云服务的网站种子采集器,还能发送到邮箱,你不来考虑一下?
  7. 为什么merge的时候要用squash
  8. 扫描身份证自动识别,自动拍照。
  9. An internal error occurred during: reload maven project. eclipse 报错
  10. 英语一和英语二的区别