当前位置: 首页 > 图文教程 > Java技术 > Web框架 > Web框架:FreeMarker中的escape , noescape指令

Web框架
Web框架:addOptions and removeAllOptions
Web框架:Xfire与Spring集成那些事
Web框架:多个dwr.xml配置方法
Web框架:小编整理Hibernate 基本查詢
Web框架:DWR使用中的web.xml配置
Web框架:Struts2使用Spring插件完成整合
Web框架:小编叙Spring的事务管理
Web框架:Struts2国际化实现用户自行选择语言
Web框架:Struts2中加载资源文件的方式
Web框架:Struts2中整合图表工具JFreeChart的时间顺序图
Web框架:浅谈Struts2的内建校验器
Web框架:FreeMarker中的escape , noescape指令
Struts2的Visitor校验器
Struts2中的subset标签使用方法浅谈
Hibernate核心接口那些事
Spring中的依赖注入
Spring中的Inversion of Control 容器
浅析Spring中的单元测试
用StrutsTestCase测试Struts应用程序
浅谈Struts中html:options的使用

Web框架:FreeMarker中的escape , noescape指令


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-12-26   浏览: 286 ::
收藏到网摘: n/a

escape指令导致body区的插值都会被自动加上escape表达式,但不会影响字符串内的插值,只会影响到body内出现的插值,使用escape指令的语法格式如下:

<#escape identifier as expression>...

<#noescape>...</#noescape>

</#escape>

 

看如下的代码:

<#escape x as x?html>

First name:${firstName}

Last name:${lastName}

Maiden name:${maidenName}

</#escape>

上面的代码等同于:

First name:${firstName?html}

Last name:${lastName?html}

Maiden name:${maidenName?html}

 

escape指令在解析模板时起作用而不是在运行时起作用,除此之外,escape指令也嵌套使用,escape继承父escape的规则,如下例子:

<#escape x as x?html>

Customer Name:${customerName}

Items to ship;

<#escape x as itemCodeToNameMap[x]>

   ${itemCode1}

   ${itemCode2}

   ${itemCode3}

   ${itemCode4}

</#escape>

</#escape>

上面的代码类似于:

Customer Name:${customerName?html}

Items to ship;

${itemCodeToNameMap[itemCode1]?html}

${itemCodeToNameMap[itemCode2]?html}

${itemCodeToNameMap[itemCode3]?html}

${itemCodeToNameMap[itemCode4]?html}

 

对于放在escape指令中所有的插值而言,这此插值将被自动加上escape表达式,如果需要指定escape指令中某些插值无需添加escape表达式,则应该使用noescape指令,放在noescape指令中的插值将不会添加escape表达式.