标准表达式语法
- message 国际化资源文件内容语法:#{}
- 没有参数的:#{home.welcome}
- 带有参数的:#{home.welcome(${username})}
- 变量语法:${}
- 选中对象内语法:*{}
- 链接语法:@{}
- @{user/login} :相对页面路径
- @{/user/login}:相对Context 路径
- @{~/user/login}:相对 Server 路径
- @{http://www.baidu.com}: 绝对路径
- @{//js.baidu.com/test.js}:相同协议的绝对路径
- 片段语法:~{}
表达式基本对象:
- #ctx:上下文对象
- #vars:上下文中的变量集合,类似于 key,value 结构吧
- #locale:上下文语言环境变量
- #request
- #response
- #session
- #servletContext
表达式工具对象:
-
#exeInfo
- #messages
- #uris
- #conversions
- #dates
- #calendars
- #numbers
- #strings
- #objects
- #bools
- #arrays
- #lists
- #sets
- #maps
- #aggregates
- #ids
标签属性:
- th:text
- th:remove
- all
- body
- tag
- all-but-first
- none
- th:utext
- th:assert
- th:insert
- th:replace
- th:if:判断if 条件的,配合使用LazyContextVariable 对象可以增强性能
- th:if="${not #lists.isEmpty(prod.comments)}
- th:with:好像是赋值变量的,th:with="name=${username}"
- th:unless:与 if 的意思相反
- th:each:循环
- 循环集合:th:each="prod : ${prods}"状态变量:th:each="prod,iterState : ${prods}",iterState(如果不指定名称,默认是单个对象的变量名后加 Stat,这个例子中是prodStat)中有以下属性
- index:循环下标,0开始
- count: 第几个,1开始
- size:共几个
- current:当前的对象
- even:是否是单数行
- odd:是否是双数行
- first:第一个吗?boolean
- last:最后一个吗?boolean
- th:switch:多个值与此进行对比如果相同则执行,th:switch="${user.role}"
- th:case:只要一个 case 为 true 其他的都为 false ,指定默认设置th:case="*"
- th:attr
- 设置单个属性:th:attr="src@{/images/1.png}"
- 设置多个属性:th:attr="src@{/images/1.png},title=#{appTitle}"
- th:attrappend:在指定属性原值之后追加,th:attrapppend="class=${\' \' +cssClassName}"
- th:classappend:在 class 后追加
- th:styleappend:在 style 后追加
- th:attrprepend:在指定属性原值之前追加,th:attrprepend="name=${\'obj.\'}"
- 有待测试
- th:checked:动态增加 checked 属性和值,true 则选中,false 则移除 checked 属性,th:checked="${user.active}"
- th:* : 设置任意的属性值
注意:标签内容替换需要unescape 的使用th:utext,需要 escape 的使用th:text。
标签
- th:block