FreeMarker學習(常用表達式)


  • 直接指定值
    • 字符串: "Foo" 或者 'Foo' 或者 "It's \"quoted\"" 或者 'It\'s "quoted"' 或者 r"C:\raw\string"
    • 數字: 123.45
    • 布爾值: true, false
    • 序列: ["foo", "bar", 123.45]; 值域: 0..90..<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_casepath?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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM