我正在使用Java模板引擎Rythm(是)。
这个想法是要替换模板文件(例如文本文件)中的占位符。
就我而言,我正在处理JSON。要调用Rythm引擎,我只需要做:
Rythm.render("my @var1 content and my email is joe@acme (or call @var2)", "foo", "bar");
输出是
[DEBUG] org.rythmengine.RythmEngine:69 - Rythm-1.1.1- SNAPSHOT started in prod mode
my foo content and my email is joebar (or call )
[ INFO] org.rythmengine.RythmEngine:84 - Shutting down Rythm Engine: [re-wZ5]
如您所见,值
"bar"
传递给@acme,引擎将其误认为是占位符。如何转义@符号?谢谢
最佳答案
您可以将@
加倍以对其进行转义:joe@acme
=> joe@@acme
在http://rythmengine.org/doc/template_guide.md#at处签出文档
编辑-添加示例代码
System.out.println(Rythm.render("my @var1 content and my email is joe@@acme.com (or call @var2)", "foo", "bar", "foo", "bar"));
产量
[DEBUG] org.rythmengine.RythmEngine:69 - Rythm-1.1.1-SNAPSHOT started in prod mode
my foo content and my email is [email protected] (or call bar)
[ INFO] org.rythmengine.RythmEngine:84 - Shutting down Rythm Engine: [re-pI7]