创建 html
另外其他标签自行添加
使用文本
语法 | 说明 |
---|---|
{home.welcome} | 使用国际化文本,国际化传参直接追加(value…) |
${user.name} | 使用会话属性 |
@{} |
|
– | – |
${} 中预存对象(表达式中基本对象) | |
param | 获取请求参数,比如${param.name},http://localhost:8080?name=jeff |
session | 获取 session 的属性 |
application | 获取 application 的属性 |
execInfo | 有两个属性 templateName和 now(是 java 的 Calendar 对象) |
ctx | |
vars | |
locale | |
httpServletRequest | |
httpSession | |
– | – |
th扩展标签 | |
th:text | 普通字符串 |
th:utext | 转义文本 |
th:href | |
th:attr |
|
th:with | 定义常量 |
th:attrappend | |
th:classappend | |
th:styleappend |
其他th标签
* | * | * |
---|---|---|
th:abbr | th:accept | th:accept-charset |
th:abbr | th:accept | th:accept-charset |
th:accesskey | th:action | th:align |
th:alt | th:archive | th:audio |
th:autocomplete | th:axis | th:background |
th:bgcolor | th:border | th:cellpadding |
th:cellspacing | th:challenge | th:charset |
th:cite | th:class | th:classid |
th:codebase | th:codetype | th:cols |
th:colspan | th:compact | th:content |
th:contenteditable | th:contextmenu | th:data |
th:datetime | th:dir | th:draggable |
th:dropzone | th:enctype | th:for |
th:form | th:formaction | th:formenctype |
th:formmethod | th:formtarget | th:frame |
th:frameborder | th:headers | th:height |
th:high | th:href | th:hreflang |
th:hspace | th:http-equiv | th:icon |
th:id | th:keytype | th:kind |
th:label | th:lang | th:list |
th:longdesc | th:low | th:manifest |
th:marginheight | th:marginwidth | th:max |
th:maxlength | th:media | th:method |
th:min | th:name | th:optimum |
th:pattern | th:placeholder | th:poster |
th:preload | th:radiogroup | th:rel |
th:rev | th:rows | th:rowspan |
th:rules | th:sandbox | th:scheme |
th:scope | th:scrolling | th:size |
th:sizes | th:span | th:spellcheck |
th:src | th:srclang | th:standby |
th:start | th:step | th:style |
th:summary | th:tabindex | th:target |
th:title | th:type | th:usemap |
th:value | th:valuetype | th:vspace |
th:width | th:wrap | th:xmlbase |
th:xmllang | th:xmlspace | th:alt-title 或th:lang-xmllang(如果其中两个属性值相同) |
对于 html5 元素名称的另一种友好写法
...
...
表达式语法
简单表达式语法
-
#{...}
: Message 表达式
Welcome to our grocery store, Sebastian Pepper!
Welcome to our grocery store, Sebastian Pepper!
-
${}
:变量表达式
ongl标准语法,方法也可以被调用
-
*{}
:选择变量表达式
Name: Sebastian.
Surname: Pepper.
Nationality: Saturn.
等价于
Name: Sebastian.
Surname: Pepper.
Nationality: Saturn.
当然了,这两者可以混合使用
还有一种方式
Name: Sebastian.
Surname: Pepper.
Nationality: Saturn.
-
@{}
: 链接 URL 表达式
view
view
view
2、变量
分类 | 示例 |
---|---|
文本 | ‘one text’ , ‘Another one!’ ,… |
数字 | 0 , 34 , 3.0 , 12.3 ,… |
真假 | true , false |
文字符号 | one , sometext , main ,… |
3、字符连接
分类 | 示例 | ||||
---|---|---|---|---|---|
+ | ‘The name is ‘+${name} | ||||
… | The name is ${name} |
4、 算数运算
语法 | 示例 |
---|---|
+, -, *, /, % | 二元运算符 |
- | 减号(一元运算符) |
5、 真假运算
分类 | 示例 |
---|---|
and , or | 二元运算符 |
! , not | 否定(一元运算符) |
6、比较运算
分类 | 示例 |
---|---|
>, <, >=, <= (gt, lt, ge, le) | 比较 |
== , != ( eq , ne ) | 平等 |
7、 条件运算
分类 | 示例 |
---|---|
if-then | (if) ? (then) |
if-then-else | (if) ? (then) : (else) |
Default | (value) ?: (defaultvalue) |
综合示例:
'User is of type ' + (${user.isAdmin()} ? 'Administrator' : (${user.type} ?: 'Unknown'))
4、表达式中使用内置对象
#dates :
utility methods for java.util.Date objects: formatting, component extraction, etc. #calendars : analogous to #dates , but for java.util.Calendar objects.
#numbers :
utility methods for formatting numeric objects.
#strings :
utility methods for String objects: contains, startsWith, prepending/appending, etc. #objects : utility methods for objects in general.
#bools :
utility methods for boolean evaluation. #arrays : utility methods for arrays.
#lists :
utility methods for lists.
#sets :
utility methods for sets.
#maps :
utility methods for maps.
#aggregates :
utility methods for creating aggregates on arrays or collections.
#messages :
utility methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{...} syntax.
#ids :
utility methods for dealing with id attributes that might be repeated (for example, as a result of an iteration).
5、预处理
__${expression}__
6、循环
Onions
2.41
yes
迭代器的状态
index: 当前的索引,从0开始
count: 当前的索引,从1开始
size:总数
current:
even/odd:
first
last
NAME
PRICE
IN STOCK
Onions
2.41
yes
7、判断
if
view
unless
view
switch
User is an administrator
User is a manager
User is an administrator
User is a manager
User is some other thing
8、模板布局
th:fragment
示例
templates/footer.html
© 2011 The Good Thymes Virtual Grocery