我在我的项目中使用 JODReports (http://jodreports.sourceforge.net/) 来生成文档。问题在于 '[#if...]' 指令中的 'AND' 逻辑运算。示例(在“.odt”模板中):
[#if entry1?? AND entry2??]bla bla[/#if]
如果存在“entry1”和“entry2”并且它们不是空值,则应该写为“bla bla”,但是在解析模板时出现错误:
freemarker.core.ParseException: Encountered "AND" at line 4, column 30424 in content.xml.
Was expecting one of:
">" ...
"." ...
"[" ...
"(" ...
"?" ...
"!" ...
<TERMINATING_EXCLAM> ...
"??" ...
"+" ...
"-" ...
"*" ...
"/" ...
"%" ...
"!=" ...
"=" ...
"==" ...
">=" ...
<ESCAPED_GTE> ...
">" ...
<ESCAPED_GT> ...
<LESS_THAN_EQUALS> ...
<LESS_THAN> ...
".." ...
<AND> ...
<OR> ...
at freemarker.core.FMParser.generateParseException(FMParser.java:4697)
at freemarker.core.FMParser.jj_consume_token(FMParser.java:4568)
at freemarker.core.FMParser.If(FMParser.java:1171)
at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:2372)
at freemarker.core.FMParser.Content(FMParser.java:2618)
at freemarker.core.FMParser.OptionalBlock(FMParser.java:2786)
at freemarker.core.FMParser.List(FMParser.java:1257)
at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:2375)
at freemarker.core.FMParser.Content(FMParser.java:2618)
at freemarker.core.FMParser.OptionalBlock(FMParser.java:2786)
at freemarker.core.FMParser.Escape(FMParser.java:2302)
at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:2445)
at freemarker.core.FMParser.Content(FMParser.java:2618)
at freemarker.core.FMParser.OptionalBlock(FMParser.java:2786)
at freemarker.core.FMParser.Root(FMParser.java:2958)
at freemarker.template.Template.<init>(Template.java:149)
at freemarker.template.Template.<init>(Template.java:172)...
这很奇怪,因为“AND”在预期语句列表中。更改模板为:
[#if (entry1??) AND (entry2??)]bla bla[/#if]
[#if entry1?? <AND> entry2??]bla bla[/#if]
[#if (entry1??) <AND> (entry2??)]bla bla[/#if]
[#if (entry1)?? AND (entry2)??]bla bla[/#if]
[#if entry1?? [AND] entry2??]bla bla[/#if]
[#if (entry1??) [AND] (entry2??)]bla bla[/#if]
也不起作用。使用 '&&' 或 '&' 而不是 'AND' 会给我错误:
freemarker.core.ParseException: Encountered ";" at line 4, column 30430 in content.xml.
Was expecting one of:
">" ...
"." ...
"[" ...
"(" ...
"?" ...
"!" ...
<TERMINATING_EXCLAM> ...
"??" ...
"+" ...
"-" ...
"*" ...
"/" ...
"%" ...
"!=" ...
"=" ...
"==" ...
">=" ...
<ESCAPED_GTE> ...
">" ...
<ESCAPED_GT> ...
<LESS_THAN_EQUALS> ...
<LESS_THAN> ...
".." ...
<AND> ...
<OR> ...
at freemarker.core.FMParser.generateParseException(FMParser.java:4697)
at freemarker.core.FMParser.jj_consume_token(FMParser.java:4568)
at freemarker.core.FMParser.If(FMParser.java:1171)
at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:2372)
at freemarker.core.FMParser.Content(FMParser.java:2618)
at freemarker.core.FMParser.OptionalBlock(FMParser.java:2786)
at freemarker.core.FMParser.List(FMParser.java:1257)
at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:2375)
at freemarker.core.FMParser.Content(FMParser.java:2618)
at freemarker.core.FMParser.OptionalBlock(FMParser.java:2786)
at freemarker.core.FMParser.Escape(FMParser.java:2302)...
我当然可以写两个“[#if]”指令——像这样:[#if entry1??][#if entry2??]bla bla[/#if][/#if]
——但我不想那样做。有什么建议么?
谢谢, 阿雷克