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

Web框架
Web框架介绍---SpringMVC
基于Django框架的敏捷Web开发
驾驭新的Ruby Web框架Waves
JAVA脚本取得struts2 OgnlValueStack中的值
Struts中DownloadAction的使用
优化Hibernate性能的几点建议
Hibernate高级查询实战
对于Struts和Spring两种MVC框架的比较
JSF与Struts的比较 超易懂!
hibernate 主键生成方式
spring acegi 官方例子
获取ApplicationContext的几种方式
Spring与自动调度任务 基于Timer的任务调度器的应用
spring+hibernate 的包的详解,帮你了解每个包的作用以及是否必要导入工程
hibernate 一对一(one to one)级联保存
struts formbean 就是鸡肋
Struts中常用的几种Action
spring的应用事例
struts2(一)
struts2(二)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-12-26   浏览: 284 ::
收藏到网摘: 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表达式.