- 直接指定值
- 字符串:
"Foo"
或者'Foo'
或者"It's \"quoted\""
或者'It\'s "quoted"'
或者r"C:\raw\string"
- 數字:
123.45
- 布爾值:
true
,false
- 序列:
["foo", "bar", 123.45]
; 值域:0..9
,0..<10
(或0..!10
),0..
- 哈希表:
{"name":"green mouse", "price":150}
- 字符串:
- 檢索變量
- 頂層變量:
user
- 從哈希表中檢索數據:
user.name
,user["name"]
- 從序列中檢索數據:
products[5]
- 特殊變量:
.main
- 頂層變量:
- 字符串操作
- 插值(或連接):
"Hello ${user}!"
(或"Hello " + user + "!"
) - 獲取一個字符:
name[0]
- 字符串切分: 包含結尾:
name[0..4]
,不包含結尾:name[0..<5]
,基於長度(寬容處理):name[0..*5]
,去除開頭:name[5..]
- 插值(或連接):
- 序列操作
- 連接:
users + ["guest"]
- 序列切分:包含結尾:
products[20..29]
, 不包含結尾:products[20..<30]
,基於長度(寬容處理):products[20..*10]
,去除開頭:products[20..]
- 連接:
- 哈希表操作
- 連接:
passwords + { "joe": "secret42" }
- 連接:
- 算術運算:
(x * 1.5 + 10) / 2 - y % 100
- 比較運算:
x == y
,x != y
,x < y
,x > y
,x >= y
,x <= y
,x lt y
,x lte y
,x gt y
,x gte y
, 等等。。。。。。 - 邏輯操作:
!registered && (firstVisit || fromEurope)
- 內建函數:
name?upper_case
,path?ensure_starts_with('/')
- 方法調用:
repeat("What", 3)
- 處理不存在的值:
- 默認值:
name!"unknown"
或者(user.name)!"unknown"
或者name!
或者(user.name)!
- 檢測不存在的值:
name??
或者(user.name)??
- 默認值:
- 賦值操作:
=
,+=
,-=
,*=
,/=
,%=
,++
,--
參考原文 http://freemarker.foofun.cn/dgui_quickstart_basics.html