0
我有这样的事情:Stringtemplate - 使用条件而不向输出添加换行符,并仍保持模板可读?
properties(attributeInfo) ::= <<
private <attributeInfo:parameters()>;
>>
parameters(attributeInfo) ::= <<
<if(attributeInfo.struct||attributeInfo.array)><attributeInfo:paramComposite()><else><javaTypeNameMap.(attributeInfo.typeName)> <attributeInfo.propertyName><endif>
>>
这将产生所需的输出:
private com.terradatum.common.db.model.terradatum.MlsAgentIdObj agentObj;
private String officeName;
private String officeAddress;
private String officeCity;
private String officeState;
private String officeZipcode;
private MlsPhoneTbl phoneTbl;
private String agentEmail;
private String agentAddress;
private String agentCity;
private String agentState;
private String agentZipcode;
当我改变parameters
子模板以下几点:
parameters(attributeInfo) ::= <<
<if(attributeInfo.struct||attributeInfo.array)><attributeInfo:paramComposite()>
<else><javaTypeNameMap.(attributeInfo.typeName)> <attributeInfo.propertyName>
<endif>
>>
模板更为清晰可辨,但输出现在包含换行符:
private com.terradatum.common.db.model.terradatum.MlsAgentIdObj agentObj
;
private String officeName
;
private String officeAddress
;
private String officeCity
;
private String officeState
;
private String officeZipcode
;
private MlsPhoneTbl phoneTbl
;
private String agentEmail
;
private String agentAddress
;
private String agentCity
;
private String agentState
;
private String agentZipcode
;
我很困惑这种行为 - 基于我了解如何有条件地包含子模板以及条件WRT对换行符的行为,parameters
子模板的两种形式应产生相同的输出。
显然我的理解是不正确的,所以我希望有人会给我一些指导。
这样做绝对是个诀窍 - 它仍然是挑战,但绝对更清晰。 – rbellamy