FreeMarker 2.3.23 發布,Java 模板引擎

jopen 9年前發布 | 21K 次閱讀 FreeMarker

按照計劃,FreeMarker 2.3.23 版正式發布,在模版和 Java 處理上有很多改動,更新日志:

FTL 方面的改進

  • Listing (#list) has received some specialized convenience features that target typical tasks people do again and again in templates.

  • Added convenience assignment operators

  • Added the then built-in, which can be used like a ternary operator

  • Added the switch built-in, which can be used like an in-line (expression) switch-case-default statement

  • Added camel case support for the identifiers that are part of the template language (user defined names aren't affected).

  • Added new special variables, .current_template_name and .main_template_name

  • Smaller error message improvements.

  • Bug fixed, activated with setting incompatible_improvements to 2.3.23

  • </ul>

    Java 方面的改進

    • Added  Configuration.setNamingConvention(int).

    • Configuration (and in fact any Configurable) setting names now can be written with camel case as well.

    • Added Configuration.setTemplateUpdateDelayMilliseconds(long) and Configuration.getTemplateUpdateDelayMilliseconds().

    • The template_update_delay setting, when specified as a string (as inside              java.util.Properties), supports time units,  like in template_update_delay=500 ms.

    • Added Environment.getCurrentTemplate()  method,

    • Added WebappTemplateLoader.setAttemptFileAccess(boolean)

    • In the FreemarkerServlet TemplatePath init-param, paths (like /templates) can have a ?settings(...)  postfix, with which you can set the JavaBean properties of the resulting TemplateLoader.

    • Added FileTemplateLoader.setEmulateCaseSensitiveFileSystem(boolean)

    相比 2.3.23 RC1 的改進:

    • .current_name_name and .main_template_name is now missing (null) instead of "" if the template has no name

    • Some minor error message improvements

    • Documentation refinements

    詳細請看發行說明:http://freemarker.org/docs/versions_2_3_23.html 

    FreeMarker是一個模板引擎,一個基于模板生成文本輸出的通用工具,使用純Java編寫

    FreeMarker被設計用來生成HTML Web頁面,特別是基于MVC模式的應用程序

    雖然FreeMarker具有一些編程的能力,但通常由Java程序準備要顯示的數據,由FreeMarker生成頁面,通過模板顯示準備的數據(如下圖)

    FreeMarker 2.3.23 發布,Java 模板引擎

    FreeMarker不是一個Web應用框架,而適合作為Web應用框架一個組件

    FreeMarker與容器無關,因為它并不知道HTTP或Servlet;FreeMarker同樣可以應用于非Web應用程序環境

    FreeMarker更適合作為Model2框架(如Struts)的視圖組件,你也可以在模板中使用JSP標記庫

     

    FreeMarker特性

    1、通用目標

    能夠生成各種文本:HTMLXMLRTFJava源代碼等等

    易于嵌入到你的產品中:輕量級;不需要Servlet環境

    插件式模板載入器:可以從任何源載入模板,如本地文件、數據庫等等

    你可以按你所需生成文本:保存到本地文件;作為Email發送;從Web應用程序發送它返回給Web瀏覽器

    2、強大的模板語言

    所有常用的指令:includeif/elseif/else、循環結構

    在模板中創建和改變變量

    幾乎在任何地方都可以使用復雜表達式來指定值

    命名的宏,可以具有位置參數和嵌套內容

    名字空間有助于建立和維護可重用的宏庫,或者將一個大工程分成模塊,而不必擔心名字沖突

    輸出轉換塊:在嵌套模板片段生成輸出時,轉換HTML轉義、壓縮、語法高亮等等;你可以定義自己的轉換

    3、通用數據模型

    FreeMarker不是直接反射到Java對象,Java對象通過插件式對象封裝,以變量方式在模板中顯示

    你可以使用抽象(接口)方式表示對象(JavaBeanXML文檔、SQL查詢結果集等等),告訴模板開發者使用方法,使其不受技術細節的打擾

    4、為Web準備

    在模板語言中內建處理典型Web相關任務(如HTML轉義)的結構

    能夠集成到Model2 Web應用框架中作為JSP的替代

    支持JSP標記庫

    MVC模式設計:分離可視化設計和應用程序邏輯;分離頁面設計員和程序員

    5、智能的國際化和本地化

    字符集智能化(內部使用UNICODE

    數字格式本地化敏感

    日期和時間格式本地化敏感

    US字符集可以用作標識(如變量名)

    多種不同語言的相同模板

    6、強大的XML處理能力

    <#recurse> <#visit>指令(2.3版本)用于遞歸遍歷XML

    在模板中清楚和直覺的訪問XML對象模型

     本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
     轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
     本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!