论坛首页 Java企业应用论坛

[提问]freemarker怎么对特殊字符转义?

浏览 14666 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-02-05  
在写自己的代码生成器,在用freemarker生成ftl模板的时候,有些ftl代码不需要在生成的时候就转化
<@ww action="${foo}">
</@ww>
${${bar}}

这些会导致异常出现
   发表时间:2006-02-05  
foo?replace('xxx', 'yyy')
0 请登录后投票
   发表时间:2006-02-05  
chenggn 写道
foo?replace('xxx', 'yyy')

跟替换字符串有什么关系?
我只想处理${foo}和${bar}
而<@ww></@ww>不处理直接输出
如果${bar}值为user.username
希望${${bar}}输出为${user.username}
0 请登录后投票
   发表时间:2006-02-05  
${"<" + "@ww"}

${"$" + "{" + bar + "}"}
0 请登录后投票
   发表时间:2006-02-05  
chenggn 写道
${"<" + "@ww"}

${"$" + "{" + bar + "}"}


可以了,谢谢,不过这样代码看起来很别扭
0 请登录后投票
   发表时间:2006-02-06  
$符号怎么转倒没注意过,别的全可以跟html一样的弄,比如
> 用 >
< 用 <
0 请登录后投票
   发表时间:2006-02-07  
${r"${build.dir}"} 
${'$’}{build.dir}
<#noescape>${build.dir}</noescape>

Max提到了这个问题
http://blog.hibernate.org/cgi-bin/blosxom.cgi/2006/02/03#a_story_about_freemarker_and_velocity
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics