webx-模板服务

来源:互联网 发布:java 数组长度 long 编辑:程序博客网 时间:2024/05/02 00:57

(1)概述

              1.什么是template

                  在生成html的时候,其中可能有一部分数据是动态生成的,那么我们可以以模板为基础,将动态内容结合到模板中,最终输出整个html文档

              2.什么是template service

                  模板引擎有多种,比如jsp、freemaker、velocity等,为了能够便于使用,于是webx提供了TemplateService,屏蔽了各个引擎之间的细节与区别,所以在使用的时候直接使用TemplateService即可


(2)使用

              1.配置

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <services:template searchExtensions="true">  
  2.     <tpl-engines:velocity-engine templateEncoding="UTF-8" strictReference="false" path="/${component}/templates">  
  3.         <global-macros>  
  4.             <name>global/*.vm</name>  
  5.         </global-macros>  
  6.         <plugins>  
  7.             <vm-plugins:escape-support defaultEscape="html">  
  8.                 <noescape>  
  9.                     <if-matches pattern="^control\." />  
  10.                     <if-matches pattern="^screen_placeholder" />  
  11.                     <if-matches pattern="^stringEscapeUtil\.escape" />  
  12.                     <if-matches pattern="^csrfToken\.(get)?(\w*)hiddenField" />  
  13.                 </noescape>  
  14.             </vm-plugins:escape-support>  
  15.         </plugins>  
  16.     </tpl-engines:velocity-engine>  
  17.     <tpl-engines:freemarker-engine templateEncoding="UTF-8" path="/${component}/templates" />  
  18.     <tpl-engines:jsp-engine path="/${component}/templates" />  
  19. </services:template>  


         <1>service:template配置
                cacheEnabled:表示是否保存模板搜索的结果,默认值会根据productionMode改变

                defaultExtension:表示模板的默认后缀

                searchLocalizedTemplates:表示是否根据当前local,搜索最合适的localized模板

                searchExtensions:表示是否让TemplateService搜索可用的模板名后缀


         <2>velocity-engine配置

                 global-macros:用来定义全局宏

                 vm-plugins:表示velocity的插件配置

                 noescape:表示不转义。也就是velocity渲染时候,如果匹配了正则的内容,就不对这块内容进行转义

0 0
原创粉丝点击