Thymeleaf的局部变量定义在模块里,并且只有在此模块生效。
...
prod 变量只有在此TR里才生效。
Thymeleaf提供一种定义变量的方式来取代迭代。
The name of the first person is Julius Caesar.
当th:with被加工后,firstPer的局部变量被创建,并且有效范围是此div内。
你同时可以定义多个局部变量。如:
The name of the first person is Julius Caesar.
But the name of the second person is Marcus Antonius.
此th:with支持重复使用已经定义的局部变量,如:
...
让我们使用局部变量来优化如下配置界面吧,尤其是日期格式化在下面多次用到的时候:
Today is:13 february 2011Nextday is:13 february 2011
首先日期的显示方式放在配置文件里home_zh.properties :
date.format=MMMM dd'','' yyyy
接下来我们修改上述模板:
Today is: 13 February 2011Nextday is:13 february 2011
事实上,th:with的优先级高于th:text,所以我们可以合并起来用。如下:
Today is:13 February 2011